【发布时间】:2017-02-13 08:59:23
【问题描述】:
我正在尝试获取字符串的哈希:
hs = hashlib.sha256(get_some_string()).hexdigest()
...但我得到一个错误:
TypeError: Unicode 对象必须在散列之前进行编码
【问题讨论】:
标签: python python-3.x hash
我正在尝试获取字符串的哈希:
hs = hashlib.sha256(get_some_string()).hexdigest()
...但我得到一个错误:
TypeError: Unicode 对象必须在散列之前进行编码
【问题讨论】:
标签: python python-3.x hash
使用utf-8编码:
hs = hashlib.sha256(get_some_string().encode('utf-8')).hexdigest()
如需了解更多信息,请阅读documentation。
【讨论】: