python - How to fix Unicode encode error using the hashlib module? -
python - How to fix Unicode encode error using the hashlib module? -
after multiple searches have not been able determine how avoid error stating: "unicode-objects must encoded before hashing" when using code:
pwdinput = input("now come in password:") pwd = hashlib.sha1() pwd.update(pwdinput) pwd = pwd.hexdigest() how can past error? how encode unicode-objects?
pwdinput = input("now come in password:").encode('utf-8') # or whatever encoding wish utilize
assuming you're using python 3, convert unicode string returned input() bytes object encoded in utf-8, or whatever encoding wish use. previous versions of python have well, handling of unicode vs. non-unicode strings bit messy, whereas python 3 has explicit distinction between unicode strings (str) , immutable sequences of bytes may or may not represent ascii characters (bytes).
http://docs.python.org/library/stdtypes.html#str.encode http://docs.python.org/py3k/library/stdtypes.html#str.encode
python unicode hashlib
Comments
Post a Comment