AttributeError: 'str' object has no attribute 'decode'

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

posted @ 2019-09-24 22:49  君莫笑我十年游  阅读(62241)  评论(0编辑  收藏  举报