views:

59

answers:

5
+1  Q: 

md5 module error

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

+1  A: 

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

Dyno Fu
Tried that already, but it breaks the script then. AttributeError: "'builtin_function_or_method' object has no attribute 'new'"
Nimbuz
well, then the 2 md5 are not the same thing, you may need to 1) rewrite the old code, 2) use python < 2.5, or 3) ignore the warning.
Dyno Fu
+2  A: 

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.

Ignacio Vazquez-Abrams
A: 

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

ghostdog74
A: 

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"

appusajeev
+1  A: 

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.

telliott99