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文件處理時出現(xiàn);
知識點與解決:
conn?=?sqlite3.connection("?...?")
conn.text_factory?=?str
設置python使用什么類型來處理sqlite3的text類型,默認是unicode,所以才會產(chǎn)生
OperationalError:?Could?not?decode?to?UTF-8?column?'name'?with?text?'國內其他'
這個錯誤
因為從數(shù)據(jù)庫中取出數(shù)據(jù)時,是gbk編碼(因為你上次存進去的是gbk)
conn.text_factory的默認值是unicode,python會嘗試將text類型的字段轉換成unicode,就產(chǎn)生了錯誤
總結
以上是生活随笔為你收集整理的python运行出现数据错误_Python运行出错情况的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 4月18日 MySQL学习
- 下一篇: 基础的python程序_Python程序