md5模块错误

发布于 2024-08-17 19:59:07 字数 269 浏览 2 评论 0原文

我正在使用旧版本的 PLY,它使用 md5 模块(以及其他模块):

import re, types, sys, cStringIO, md5, os.path

...尽管脚本运行但并非没有此错误:

DeprecationWarning: the md5 module is deprecated; use hashlib instead

如何修复它以使错误消失?

谢谢

I'm using an older version of PLY that uses the md5 module (among others):

import re, types, sys, cStringIO, md5, os.path

... although the script runs but not without this error:

DeprecationWarning: the md5 module is deprecated; use hashlib instead

How do I fix it so the error goes away?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

杯别 2024-08-24 19:59:07

我认为警告消息非常简单。你需要:

from hashlib import md5

或者你可以使用 python < 2.5、http://docs.python.org/library/md5.html

I think the warning message is quite straightforward. You need to:

from hashlib import md5

or you can use python < 2.5, http://docs.python.org/library/md5.html

旧人哭 2024-08-24 19:59:07

这不是错误,这是警告。

如果您仍然坚持摆脱它,请修改代码,以便它使用 hashlib< /code>相反。

That's not an error, that's a warning.

If you still insist on getting rid of it then modify the code so that it uses hashlib instead.

北笙凉宸 2024-08-24 19:59:07

如前所述,警告可以被静音。 hashlib.md5(my_string) 应该与 md5.md5(my_string) 执行相同的操作。

>>> import md5
__main__:1: DeprecationWarning: the md5 module is deprecated; use hashlib instead
>>> import hashlib
>>> s = 'abc'
>>> m = md5.new(s)
>>> print s, m.hexdigest()
abc 900150983cd24fb0d6963f7d28e17f72
>>> m = hashlib.md5(s)
>>> print s, m.hexdigest()
abc 900150983cd24fb0d6963f7d28e17f72
>>> md5(s)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'module' object is not callable
>>> md5.md5(s)
<md5 HASH object @ 0x100493260>
>>> m = md5.md5(s)
>>> print s, m.hexdigest()
abc 900150983cd24fb0d6963f7d28e17f72

正如 @Dyno Fu 所说:您可能需要跟踪代码实际从 md5 调用的内容。

As mentioned, the warning can be silenced. And hashlib.md5(my_string) should do the same as md5.md5(my_string).

>>> import md5
__main__:1: DeprecationWarning: the md5 module is deprecated; use hashlib instead
>>> import hashlib
>>> s = 'abc'
>>> m = md5.new(s)
>>> print s, m.hexdigest()
abc 900150983cd24fb0d6963f7d28e17f72
>>> m = hashlib.md5(s)
>>> print s, m.hexdigest()
abc 900150983cd24fb0d6963f7d28e17f72
>>> md5(s)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'module' object is not callable
>>> md5.md5(s)
<md5 HASH object @ 0x100493260>
>>> m = md5.md5(s)
>>> print s, m.hexdigest()
abc 900150983cd24fb0d6963f7d28e17f72

As @Dyno Fu says: you may need to track down what your code actually calls from md5.

够钟 2024-08-24 19:59:07

请参阅文档此处,28.5.3 为您提供了一种抑制弃用警告的方法。或者在运行脚本时在命令行上发出 -Wignore::DeprecationWarning

please see the docs here , 28.5.3 gives you a way to suppress deprecate warnings. Or on the command line when you run your script, issue -W ignore::DeprecationWarning

坦然微笑 2024-08-24 19:59:07

我认为警告没问题,你仍然可以使用 md5 模块,否则 hashlib 模块包含 md5 类,

import hashlib
a=hashlib.md5("foo")
print a.hexdigest()

这将打印字符串“foo”的 md5 校验和

i think the warning is ok,still you can use the md5 module,or else hashlib module contains md5 class

import hashlib
a=hashlib.md5("foo")
print a.hexdigest()

this would print the md5 checksum of the string "foo"

可爱咩 2024-08-24 19:59:07

像这样的事情怎么办?

try:
    import warnings
    warnings.catch_warnings()
    warnings.simplefilter("ignore")
    import md5
except ImportError as imp_err:
    raise type(imp_err), type(imp_err)("{0}{1}".format(
        imp_err.message,"Custom import message"))

What about something like this?

try:
    import warnings
    warnings.catch_warnings()
    warnings.simplefilter("ignore")
    import md5
except ImportError as imp_err:
    raise type(imp_err), type(imp_err)("{0}{1}".format(
        imp_err.message,"Custom import message"))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文