(Python)‘NoneType‘ object has no attribute ‘encoding‘

一、
问题介绍:
在写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.

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值