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

后端 未结 7 1220
自闭症患者
自闭症患者 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
    a = hashlib.md5(("the thing you want to hash").encode())
    
    print(a.hexdigest())
    

    you are giving nothing to hash here and since in python everything is in unicode you have to encode it to UTF-8(by default) first.

    0 讨论(0)
提交回复
热议问题