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

解决问题方案来源: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,就产生了错误

原文地址:https://www.cnblogs.com/z964166725/p/5000122.html