2017-02-13 68 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