首页 > Web开发 > 详细

‘NoneType‘ object has no attribute ‘encoding‘

时间:2020-07-16 10:10:08      阅读:41      评论:0      收藏:0      [点我收藏+]

一、

问题介绍:
在写python web时访问特定网页,出现了‘NoneType‘ object has no attribute ‘encoding‘错误。
技术分享图片

二、

查看文件mini_frame.py文件(用于处理业务逻辑的文件),发现在进行数据库连接时有编码的设定。

db=pymysql.connect(host=localhost,port=3306,user=root,password=123456,database=stock_db,charset=utf-8)
cursor=db.cursor()
sql="select * from info;"
cursor.execute(sql)
data_from_mysql=cursor.fetchall()
cursor.close()
db.close()


解决:
将utf-8给改成utf8即可。

改之后的代码如下:

db=pymysql.connect(host=localhost,port=3306,user=root,password=123456,database=stock_db,charset=utf8)
cursor=db.cursor()
sql="select * from info;"
cursor.execute(sql)
data_from_mysql=cursor.fetchall()
cursor.close()
db.close()

 


Accept what was and what is, and you’ll have more positive energy to pursue what will be.

‘NoneType‘ object has no attribute ‘encoding‘

原文:https://www.cnblogs.com/xiaofengcanyuelong/p/13320672.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!