本文主要是介绍DeprecationWarning: the md5 module is deprecated; use hashlib instead import md5,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
原来的python脚本是在Ubuntu 14.04 64bit上写的,运行没有问题,但是在CentOS 6.3上的crontab中定时执行时,每次都报
DeprecationWarning: the md5 module is deprecated; use hashlib instead import md5
脚本如下:
#/usr/bin/env python
#coding:utf-8import md5hash = md5.new()
hash.update('spam,spam,and egges')
print repr(hash.digest())
解决方法:
与系统默认安装的python版本有关,CentOS 6.3默认的版本是2.6,Ubuntu 14.04 64bit上默认的版本是2.7,改成下面的脚本就可以都兼容了。
#!/usr/bin/env python
#encoding: utf-8import types#get md5 of a specified string
def get_md5(s):if type(s) is types.StringType:try:import hashlibm = hashlib.md5()except ImportError:# for python < 2.5import md5m = md5.new()m.update(s)return repr(m.hexdigest())else:return ''if __name__ == '__main__':print get_md5("tao_627@aliyun.com")
在终端运行的结果是
这篇关于DeprecationWarning: the md5 module is deprecated; use hashlib instead import md5的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!