<分区>
我正在尝试获取字符串的哈希值:
hs = hashlib.sha256(get_some_string()).hexdigest()
...但是我得到一个错误:
TypeError: Unicode-objects must be encoded before hashing
标签 python python-3.x hash
<分区>
我正在尝试获取字符串的哈希值:
hs = hashlib.sha256(get_some_string()).hexdigest()
...但是我得到一个错误:
TypeError: Unicode-objects must be encoded before hashing
最佳答案
使用utf-8
编码:
hs = hashlib.sha256(get_some_string().encode('utf-8')).hexdigest()
要获得更多信息,请阅读 documentation .
关于python - 无法获取字符串的 sha256 哈希,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42200117/