Reputation: 1657
I have some code to hash a string in Python 3
import hashlib
hobj = hashlib.md5()
And when I use the command:
hobj.update('test')
I get the error:
TypeError: Unicode-objects must be encoded before hashing
Upvotes: 1
Views: 5498
Reputation:
Encode the string to UTF-8 (for example):
hobj.update('test'.encode("UTF-8"))
print(hobj.hexdigest())
Output:
098f6bcd4621d373cade4e832627b4f6
Upvotes: 5