问题描述:
python3.7.8版本运行python2.5脚本时报错:TypeError: Unicode-objects must be encoded before hashing
问题解析:
md5在进行哈希运算前,需要对数据进行编码。
解决办法:
指定编码格式,进行转码,修改代码如下:
# 原代码
md5_str = hashlib.md5(path).hexdigest()
# 修改后代码(进行转码,指定编码格式)
md5_str = hashlib.md5((path).encode('utf-8')).hexdigest()
再次执行脚本,运行成功!
参考:
https://www.sohu.com/a/229169868_401429
https://blog.csdn.net/weixin_45598506/article/details/112531052