hash unicode string in python

后端 未结 3 2092
难免孤独
难免孤独 2021-02-06 21:07

I try to hash some unicode strings:

hashlib.sha1(s).hexdigest()
UnicodeEncodeError: \'ascii\' codec can\'t encode characters in position 0-81: 
ordinal not in ra         


        
3条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-06 21:33

    You hash bytes, not strings. So you gotta know what bytes you really want to hash, for example an utf8 memory representation of the string or a utf16 memory representation of the string, etc.

提交回复
热议问题