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

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

    Under the different versions of Python is different,I use Python 2.7,same as you write, it works well.

    hashlib.md5(data) function, the type of data parameters should be 'bytes'.That is to say, we must put the type of data into bytes before hashes.

    Requirements before the hash code conversion, because the same string have different values under different coding systems(utf8\gbk.....), in order to ensure not happen ambiguity has to be a dominant conversion.

提交回复
热议问题