python运行出现数据错误_Python运行出错情况

1、错误内容:You must not use 8-bit bytestrings unless you use a text_factory that can interpret 8-bit bytestrings (like text_factory = str). It is highly recommended that you instead just switch your application to Unicode strings.

错误描述:Python中使用Sqlite3模块进行db文件处理时出现;

知识点与解决:

conn = sqlite3.connection(" ... ")

conn.text_factory = str

设置python使用什么类型来处理sqlite3的text类型,默认是unicode,所以才会产生

OperationalError: Could not decode to UTF-8 column 'name' with text '国内其他'

这个错误

因为从数据库中取出数据时,是gbk编码(因为你上次存进去的是gbk)

conn.text_factory的默认值是unicode,python会尝试将text类型的字段转换成unicode,就产生了错误

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值