首页 > 编程语言 > 详细

Python运行出错情况

时间:2015-11-27 13:03:53      阅读:447      评论:0      收藏:0      [点我收藏+]

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

解决问题方案来源:http://bbs.csdn.net/topics/250055755

设置python使用什么类型来处理sqlite3的text类型,默认是unicode,所以才会产生
OperationalError: Could not decode to UTF-8 column ‘name‘ with text ‘国内其他‘ 
这个错误

因为从数据库中取出数据时,是gbk编码(因为你上次存进去的是gbk)
conn.text_factory的默认值是unicode,python会尝试将text类型的字段转换成unicode,就产生了错误

Python运行出错情况

原文:http://www.cnblogs.com/z964166725/p/5000122.html

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