美文网首页程序员系列
阿里云SDK运行报错:Python3 encoding or

阿里云SDK运行报错:Python3 encoding or

作者: 王兵 | 来源:发表于2018-05-09 15:34 被阅读57次

原自然语言调用示例:

https://help.aliyun.com/document_detail/70504.html?spm=a2c4g.11186623.6.553.Qcxf9V#h2-python-4

调试阿里云 SDK 发送 request 的时候遇到问题:

/usr/local/lib/python3.6/site-packages/aliyunsdkcore/auth/utils/md5_tool.py in _get_md5(content)
     32 def _get_md5(content):
     33     m = hashlib.md5()
---> 34     m.update(bytearray(content, "utf-8"))
     35     return m.digest()

TypeError: encoding or errors without a string argument

Google 后找到答案:Python3 的 base64.b64encode() 不需要重新 decode 再 encode 故修改这个文件:

/usr/local/lib/python3.6/site-packages/aliyunsdkcore/auth/utils/md5_tool.py

in _get_md5(content)
     32 def _get_md5(content):
     33     m = hashlib.md5()
---> 34     #m.update(bytearray(content, "utf-8"))
---> 35     m.update(content)
     36     return m.digest()

问题解决。

相关文章

网友评论

本文标题:阿里云SDK运行报错:Python3 encoding or

本文链接:https://www.haomeiwen.com/subject/hctorftx.html