Tag Archives: python3.7+django2.2

[Solved] python3.7+django2.2 Error: AttributeError: ‘str’ object has no attribute ‘decode’

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!