hashlib使用时出现: 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
posted @ 2017-09-14 12:55  bingo彬哥  阅读(26742)  评论(0编辑  收藏  举报
本站总访问量