hashlib使用时出现: Unicode-objects must be encoded before hashing
2017-09-10 00:00
573 查看
# 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
# 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
相关文章推荐
- django注册在使用hashlib对密码加密时报Unicode-objects must be encoded before hashing
- hashlib使用时出现: Unicode-objects must be encoded before hashing
- TypeError: Unicode-objects must be encoded before hashing
- 关于python2.7的md5加密遇到的问题(TypeError: Unicode-objects must be encoded before hashing)
- Unicode-objects must be encoded before hashing 错误解决办法
- 使用universalimageloader框架,出现ImageLoader must be init with configuration before using
- 使用 python 的sklearn模块,训练模型时,出现 ValueError: min_samples_split must be at least 2 or in (0, 1], got 1 的
- ubuntu运行sudo命令出现“sudo: /usr/lib/sudo/sudoers.so must be only be writable by owner”的一种解决办法
- Android studio使用selector时出现Element selector must be declared的错误解决
- 使用pickle将对象存储到文件中时出现 TypeError: write() argument must be str, not bytes
- 使用 python3.6 调用 jieba 库出现的 ValueError: dictionary file dict.txt must be utf-8 错误
- ubuntu运行sudo命令出现“sudo: /usr/lib/sudo/sudoers.so must be only be writable by owner”的一种解决办法
- 我在使用redux过程中遇到Actions must be plain objects. Use custom middleware for async actions.异常的分析
- 解决使用imageload遇到ImageLoader must be init with configuration before using这种异常
- 关于 Fiddler 出现Response is encoded and may need to be decoded before inspection.
- 使用aidl隐式调用service出现service intent must be explicit 问题的一种解决方法
- Ubuntu使用sudo命令出现must be setuid root错误的解决方法
- Python出现TypeError: file() argument 1 must be encoded string without NULL bytes, not str问题解决
- .NET中使用GridView控件输入数据时出现“ Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index"的问题
- Java swing使用皮肤后出现Component creation must be done on Event Dispatch Thread错误解决方法