2017-02-13 67 views
-1

我试图得到一个字符串的哈希值的SHA256哈希:无法得到一个字符串

 hs = hashlib.sha256(get_some_string()).hexdigest() 

错误:

TypeError: Unicode-objects must be encoded before hashing 
+0

http://stackoverflow.com/questions/18877589/python-unicode-utf-8可能会帮助你 – Tschallacka

回答

1

使用utf-8编码:

hs = hashlib.sha256(get_some_string().encode('utf-8')).hexdigest() 

欲了解更多信息,请阅读documentation