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://www.cnblogs.com/qianzf/p/13468261.html