Environment: python3.7+django2.2
Error message:
AttributeError: ‘str’ object has no attribute ‘decode’
Solution:
Find the django file under the python file>db file>backends>mysql>operations.py
open a file:
Ctrl+f search query.decode after opening
Then change query.decode to query.encode
#Original code:
query = getattr(cursor, '_executed', None) if query is not None: query = query.decode(errors='replace') return query
#change into:
query = getattr(cursor, '_executed', None) if query is not None: query = query.encode(errors='replace') return query
Done!
Similar Posts:
- [Solved] Python Error: Attributeerror: ‘STR’ object has no attribute ‘decode’
- [Solved] Djiango Create Migrations Error: query = query.decode(errors=’replace’) AttributeError: ‘str’ object has no attribute ‘decode’
- Python3.x Error:AttributeError: ‘str’ object has no attribute ‘decode’
- Error reporting and resolution of Python 3 using binascii method
- attributeerror: ‘str’ object has no attribute ‘decode’
- Django: How to Solve Using Pymysql Error
- TypeError: the JSON object must be str, not ‘bytes’
- Python AttributeError: ‘unicode’ object has no attribute ‘tzinfo’
- UnicodeEncodeError: ‘ascii’ codec can’t encode characters in position 0-1:
- [Solved] Unicode decode error in the background when the robot framework is running