Python sqlite3.ProgrammingError: You must not use 8-bit bytestrings unless you use a text_factory that can interpret 8-bit bytestrings......

完整的错误信息如下:

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 recomme nded that you instead just switch your application to Unicode strings.

原因:

使用sqlite3数据库,对数据库进行操作的过程中,使用没有经过unicode解码的中文数据导致的。

举例:
category = Category.query.filter( Category.name == "上衣").first()
会报上述错误。
 
解决方案:
需要对中文进行unicode解码:
category = Category.query.filter( Category.name == u"上衣").first()
 
作者:yaoelvon@gmail.com
时间:2016/03/31
原文地址:https://www.cnblogs.com/yaoel/p/5342322.html