Python3 Unicode-objects must be encoded before hashing
# hashlib.md5(data)函数中,data参数的类型应该是bytes
# hash前必须把数据转换成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
原文地址:https://www.cnblogs.com/everfight/p/python_hashlib.html
原文地址:https://www.jianshu.com/p/b3e6dd342379
评论区