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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM