參考下面的鏈接解決這個問題(原文也引用了)
# hashlib.md5(data)函數(shù)中会烙,data參數(shù)的類型應(yīng)該是bytes
# hash前必須把數(shù)據(jù)轉(zhuǎn)換成bytes類型
>>> from hashlib import md5
File "<stdin>", line 1, in <module>
>>> c = md5("helloworld")
TypeError: Unicode-objects must be encoded before hashing
>>> c = md5("helloworld".encode("utf-8"))
>>> print(c.hexdigest())
fc5e038d38a57032085441e7fe7010b0