代码改变世界

pyOpenSSL0.13安装失败

2013-11-11 16:51 by cmsd, 1958 阅读, 0 推荐, 收藏, 编辑
摘要:/usr/lib64/python2.4/distutils/dist.py:236: UserWarning: Unknown distribution option: 'zip_safe' warnings.warn(msg)running build_extbuilding 'OpenSSL.SSL' extensiongcc -pthread -fno-strict-aliasing -DNDEBUG -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --p 阅读全文

关于django post表单

2013-10-29 14:49 by cmsd, 310 阅读, 0 推荐, 收藏, 编辑
摘要:CSRF verification failed. Request aborted.默认会出现该状况,解决办法:1.使用requestcontextfrom django.template import RequestContext……return render_to_response('my_template.html',my_data_dictionary,context_instance=RequestContext(request))2.在表单中添加tag{% csrf_token %}3.setting.py中MIDDLEWARE_CLASSES加入'djan 阅读全文

python urllib2 Basic认证

2013-10-11 18:06 by cmsd, 1901 阅读, 0 推荐, 收藏, 编辑
摘要:1.通过添加http header 来实现import urllib2from base64 import encodestringurl = 'http://202.108.1.51'user = 'a'passwd = 'aa' req = urllib2.Request(url)basestr = encodestring('%s:%s' % (user,passwd))[:-1]req.add_header('Authorization','Basic %s' % basestr)f = u 阅读全文

python ftplib,smtplib,poplib学习

2013-09-30 17:21 by cmsd, 520 阅读, 0 推荐, 收藏, 编辑
摘要:一.ftplibfrom ftplib import FTPftpobj = FTP(IP或域名) #实例化对象ftpobj.login('username','passwd') ##调用方法登录ftpobj.pwd() #当前目录ftpobj.cwd('/') #切换目录ftpobj.dir([path[,..[,cb]]) #显示path 目录里的内容,可选的参数cb 是一个回调函数,它会被传给retrlines()方法ftpobj.nlst([path[,..]) #以列表方式显示path内的内容ftpobj.r... 阅读全文

python gzip,bz2学习

2013-09-24 10:15 by cmsd, 866 阅读, 0 推荐, 收藏, 编辑
摘要:一.gzipimport gzip1.解压缩a = gzip.open('a.tar.gz')b = open('a.tar','wb')b.write(a.read())a.close()b.close()2.压缩文件b = open('c.tar','rb')c = gzip.open('c.tar.gz','wb')c.write(b.read())b.close(0c.close(0二.bz2bz2的使用方法与gz一样import bz21.解压a=bz2.BZ2File(& 阅读全文

python pickle 和 shelve模块

2013-09-16 15:16 by cmsd, 484 阅读, 0 推荐, 收藏, 编辑
摘要:pickle和shelve模块都可以把python对象存储到文件中,下面来看看它们的用法吧1.pickle 写: 以写方式打开一个文件描述符,调用pickle.dump把对象写进去 dn = {'baidu':'www.baidu.com','qq':'www.qq.com','360':'www.360.cn'} name = ['mayun','mahuateng','liyanhong'] f = open(r'C:\a.txt' 阅读全文

nexenta systemcallerror

2013-09-13 17:35 by cmsd, 243 阅读, 0 推荐, 收藏, 编辑
摘要:最近在试nexenta做iscsi,设置ip出现上面的错误解决办法,先讲mtu设置为不周与原来的值,比如原来为1500,先设置成1501,就可以了,然后可以再改回来,也是没有问题的! 阅读全文

python password输入

2013-09-11 13:32 by cmsd, 576 阅读, 0 推荐, 收藏, 编辑
摘要:1.linux下用getpass,没有星号提示,符合linux风格from getpass import getpasspwd = getpass('Enter the password: ')2.windows下用msvcrtimport msvcrt, sys def pwd_input(): chars = [] while True: newChar = msvcrt.getch() if newChar in '\r\n': # 如果是换行,则输入结束 print '' br... 阅读全文

python加密模块学习

2013-09-11 11:15 by cmsd, 625 阅读, 0 推荐, 收藏, 编辑
摘要:1. md5模块 md5.new([arg]) 返回一个md5对象,如果给出参数,则相当于调用了update(arg) md5.update(arg) 用string参数arg更新md5对象 md5.digest() 返回16字节的摘要,由传给update的string生成,摘要没有ascii字符 md5.hexdigest() 以16进制的形式返回摘要import md5a = md5.new('passwd')a.digest() 'v\xa2\x17;\xe692T\xe7/\xfaMm\xf1\x03\n'a.hexdigest() '76a21 阅读全文

time模块学习

2013-09-09 18:13 by cmsd, 294 阅读, 0 推荐, 收藏, 编辑
摘要:时间三种形式: 1.timestamp 从1970-1-1 00:00到现在经历的秒数 2.string_time Sat Mar 28 22:24:24 2009 3.struct_time 时间为9个元素的数组 year (four digits, e.g. 1998) month (1-12) day (1-31) hours (0-23) minutes (0-59) seconds (0-59) weekday (0-6, Monday is 0) Julian day (day in the year, 1-366) DST (Daylight Savings Time) fl.. 阅读全文
上一页 1 ··· 8 9 10 11 12 13 下一页