您的位置:首页 > 编程语言 > Python开发

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

2016-03-31 18:45 661 查看
完整的错误信息如下:

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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: