首页 > 技术文章 > AttributeError: 'str' object has no attribute 'decode'

zhf123 2019-09-24 22:49 原文

python3下列代码会报上边的错

print("Response:", resp.text.decode('unicode_escape'))
解决办法:
print("Response:", resp.text.encode('utf-8').decode('unicode_escape'))
中间加上.encode('utf-8')即可。

问题原因:
python3里面,字符串要先encode手动指定其为某一编码的字节码之后,才能decode解码。
原文链接:https://blog.csdn.net/IT_TIfarmer/article/details/90747496

推荐阅读