Django框架 python3.7+django2.2 报错:AttributeError: ‘str’ object has no attribute ‘decode’解决办法
2021/12/17 22:20:33
本文主要是介绍Django框架 python3.7+django2.2 报错:AttributeError: ‘str’ object has no attribute ‘decode’解决办法,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
转载于:https://blog.csdn.net/qq_41630218/article/details/89631835?spm=1001.2101.3001.6650.2&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-2.highlightwordscore&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-2.highlightwordscore
环境: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
然后就好了,问题解决!
这篇关于Django框架 python3.7+django2.2 报错:AttributeError: ‘str’ object has no attribute ‘decode’解决办法的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2025-01-03用FastAPI掌握Python异步IO:轻松实现高并发网络请求处理
- 2025-01-02封装学习:Python面向对象编程基础教程
- 2024-12-28Python编程基础教程
- 2024-12-27Python编程入门指南
- 2024-12-27Python编程基础
- 2024-12-27Python编程基础教程
- 2024-12-27Python编程基础指南
- 2024-12-24Python编程入门指南
- 2024-12-24Python编程基础入门
- 2024-12-24Python编程基础:变量与数据类型