Confusion about Hashlib - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Confusion about Hashlib (/thread-11150.html) |
Confusion about Hashlib - Vysero - Jun-25-2018 I have never used haslib before. If I understand it is a way to encode an object for compression? I have the following line giving an error: multi_inc_prot = 'MULTI_INC_PROT_%s' % hashlib.md5(sys.argv[0]).hexdigest()The error is: I tried:string = 'MULTI_INC_PROT_%s'.encode('utf-8') multi_inc_prot = string % hashlib.md5(sys.argv[0]).hexdigest()which did not work. Apparently, I am misunderstanding the error. Could someone please explain? Never mind I figured it out. It was the argument that needed encoding: multi_inc_prot = 'MULTI_INC_PROT_%s' % hashlib.md5(sys.argv[0].encode('utf-8')).hexdigest() RE: Confusion about Hashlib - Larz60+ - Jun-25-2018 usage instructions here: http://code.krypto.org/python/hashl also, please When showing code, provide enough to run a stand alone snippet (keep it as short as possible, while still creating the error) RE: Confusion about Hashlib - DeaD_EyE - Jun-25-2018 You are trying hash a str, hashlib.HASHFUNC expects bytes.Just use sys.argv[0].encode() .This encodes the unicode str to bytes. |