python运维开发-pickle序列化
pickle的使用
json是跨语言的,pickle是只能在python用,涉及序列化,反序列化
import pickle
d= {a':1,'b':2}
with open('/tmp/1.pickle','wb')as fd:
pickle.dumps(d,fd)
pickle模块应用,应用到cmdb
mysql连接django
#https://docs.djangoproject.com/en/1.6/ref/settings/
DATABASES = {
'default': {
'ENGINE':'django.db.backends.mysql',
'NAME': ‘cmdb',
'USER': 'root',
'PASSWORD': '',
'HOST': 'localhost',
'PORT': '3306',
}
}
yum -y install mysql-server
service mysqld restart
ls /var/lib/mysql
create database cmdb;
同步数据库
rm -rf db.sqlite3
yum search MySQLdb
yum install MySQLdb....
python manage.py syncdb
=====
mysql
use cmdb
show talbes;
chkconfig mysqld on
怎么去使用pickle呢?
print req.body
启动开发服务器
修改collect_info脚本
在脚本里import pickle库
#d = urllib.urlencode(dic)
d=pickle.dumps(dic)
req = urllib2.urlopen('http://192.168.17.139:8000/hostinfo/collect/',d)
把这 数据传过去
报错了。。。
在django这边反序列回来
import pickle
pickle.loads
修改views.py
obj=pickle.loads(req.body)
obj['ip']
:13,19s/req.POST.get/obj/
:13,19s/(/[/
:13,19s/)/]/
posted on 2018-01-10 12:22 linux-paul 阅读(119) 评论(0) 编辑 收藏 举报