AttributeError: 'str' object has no attribute 'decode'
今天用python3连接mysql的时候,然后修改配置后,运行
python3 manage.py runserver
的时候,出现了以下错误:
File "/data/env/pyweb/lib/python3.6/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 = query.encode(errors='replace')
首先,提示已经告诉你文件地址了
我们打开这个文件:
vim /data/env/pyweb/lib/python3.6/site-packages/django/db/backends/mysql/operations.py
搜索decode
解决方法:把decode改为encode即可。