【Django学习】在Django框架中偶遇报错:AttributeError: ‘str’ object has no attribute ‘decode’解决办法

环境: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
然后就好了,问题解决!
————————————————
版权声明:本文为CSDN博主「亭有枇杷树」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_41630218/article/details/89631835

posted @ 2022-01-12 18:52  gtea  阅读(320)  评论(0编辑  收藏  举报