DeprecationWarning: the md5 module is deprecated; use hashlib instead import md5的解决办法


今天在学习python的md5模块的时候,做练习,遇到DeprecationWarning: the md5 module is deprecated; use hashlib instead
  import md5的警告;

# /usr/bin/python
# -*- coding:utf-8 -*-

import md5
hash = md5.new()
hash.update('spam,spam,and egges')
print repr(hash.digest())

执行结果为:

解决办法:

# /usr/bin/python
# -*- coding:utf-8 -*-
try:
    import hashlib
    hash = hashlib.md5()
except ImportError:
    # for Python << 2.5
    import md5
    hash = md5.new()
hash.update('spam,spam,and egges')
print repr(hash.digest())

如代码所示,我使用的python版本是2.6.6,所以会有警告,如果是2.5之前的版本就不会有了。

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM