hashlib.md5() TypeError: Unicode-objects must be encoded before hashing

后端 未结 7 1241
自闭症患者
自闭症患者 2020-12-09 15:16

I am new to coding and have ran into a problem trying to encode a string.

>>> import hashlib
>>> a = hashlib.md5()
>>> a.update(\'         


        
7条回答
  •  悲哀的现实
    2020-12-09 15:53

    It's not working in the REPL. It's hashed nothing, since you've passed it nothing valid to hash. Try encoding first.

    3>> hashlib.md5().digest()
    b'\xd4\x1d\x8c\xd9\x8f\x00\xb2\x04\xe9\x80\t\x98\xec\xf8B~'
    3>> a = hashlib.md5()
    3>> a.update('hi'.encode('utf-8'))
    3>> a.digest()
    b'I\xf6\x8a\\\x84\x93\xec,\x0b\xf4\x89\x82\x1c!\xfc;'
    

提交回复
热议问题