在Django框架中偶遇报错:AttributeError: ‘str’ object has no attribute ‘decode’解决办法
程序员文章站
2024-03-25 11:37:52
...
环境:python3.7+django2.2
报错信息:
AttributeError: ‘str’ object has no attribute ‘decode’
解决办法:
找到python文件下的django文件>db文件>backends>mysql>operations.py
打开文件:
打开后ctrl+f搜索query.decode
然后将query.decode改为query.encode
#原代码:
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.encode(errors='replace')
return query
然后就好了,问题解决!