attributeerror: ‘str’ object has no attribute ‘decode’
The following code in Python 3 will report the above error
print(“Response:”, resp.text.decode(‘unicode_ Solution:
Print (“response:”, resp.text.encode (‘utf-8 ‘). Decode (‘unicode’)_ Escape ‘)
Add. Encode (‘utf-8’) in the middle
Reason for the problem:
in Python 3, a string must be manually specified as a bytecode by encode before it can be decoded
Similar Posts:
- Error reporting and resolution of Python 3 using binascii method
- UnicodeEncodeError: ‘ascii’ codec can’t encode characters in position 0-1:
- Python Open File SyntaxError: (unicode error) ‘unicodeescape’ codec can’t decode bytes in …
- TypeError: the JSON object must be str, not ‘bytes’
- Python:SyntaxError: (unicode error) ‘unicodeescape’ codec can’t decode bytes in pos…
- [Solved] python3.7+django2.2 Error: AttributeError: ‘str’ object has no attribute ‘decode’
- Python Files Error: SyntaxError: (unicode error) ‘unicodeescape’ codec can’t decode bytes in position 2-3: tr
- python 3.6 socket tcp Connect TypeError: a bytes-like object is required, not ‘str’
- Python3.x Error:AttributeError: ‘str’ object has no attribute ‘decode’
- How to Solve Wechat wxpy Robot Error