Search code examples
pythonattributeerror

AttributeError: 'module' object has no attribute 'a'


I am trying to learn python and trying to write a simple script. There seems to be a problem with using a raw_input created variable. I am sure it's simple, but I just don't have the background yet to figure this one out. Here is what I've tried and what works:

#!/usr/bin/python

import hashlib

v = raw_input("Enter your value: ")
print "Which hash algorithm do you want to use?"
# This fails
a = raw_input("md5, sha1, sha224, sha256, sha384, sha512: ")
h = hashlib.a(v)
h.hexdigest()

# This works

v = "password"
h = hashlib.md5(v)
h.hexdigest()

Solution

  • a is just storing a variable with a string value. hashlib.a() is just trying to call a method called a in the hashlib module (which doesnt exist). Try instead using

    h = haslib.new(a)
    h.update(v)
    h.hexdigest()