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

后端 未结 7 1221
自闭症患者
自闭症患者 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:41

    A solution that works in both py2/py3:

    from six import ensure_binary
    from hashlib import md5
    
    md5(ensure_binary('hi')).digest()
    

提交回复
热议问题