Python3 Unicode-objects must be encoded before hashing

参考下面的链接解决这个问题(原文也引用了)

  • hashlib使用时出现: Unicode-objects must be encoded before hashing
# hashlib.md5(data)函数中,data参数的类型应该是bytes
# hash前必须把数据转换成bytes类型
>>> from hashlib import md5
File "", line 1, in 
>>> c = md5("helloworld")
TypeError: Unicode-objects must be encoded before hashing
>>> c = md5("helloworld".encode("utf-8"))
>>> print(c.hexdigest())
fc5e038d38a57032085441e7fe7010b0

你可能感兴趣的:(Python3 Unicode-objects must be encoded before hashing)