django AttributeError: 'str' object has no attribute 'decode 解决方法


File "/www/wwwroot/examback/venv/lib/python3.8/site-packages/django/db/backends/mysql/operations.py", line 146, in last_executed_query query = query.decode(errors='replace') AttributeError: 'str' object has no attribute 'decode

query = getattr(cursor, '_executed', None) if query is not None: query = query.decode(errors='replace') return query

改为

query = getattr(cursor, '_executed', None) if query is not None: query = query.decode('utf-8').encode(errors='replace') return query

如果报错 query = query.decode('utf-8').encode(errors='replace') AttributeError: 'str' object has no attribute 'decode' 还不行改为 改为

query = getattr(cursor, '_executed', None) if query is not None: query = query.encode(errors='replace') return query