[英]Sqlite database non-ascii character error with python SQLalchemy library
当我将sqlite3数据库与sqlalchemy库一起使用时,出现此错误
sqlalchemy.exc.ProgrammingError: (ProgrammingError)
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.
u'INSERT INTO model_pair (user, password) VALUES (?, ?)' ('\xebE\xc2\xe4.\t312874@gg.com', '123456')
这是一些测试数据:
呆呆 3098920@gg.com 11111
�言 9707996@gg.com 11111
wwwj55572@gg?€? 11111
我已经将数据库编码配置为utf-8或gbk但是在插入时都没有成功,我尝试使用str.decode('gbk'),它会像char一样卡在char上并得到如上所述的错误。
有谁告诉我怎么解决这个错误?
尝试将'\\xebE\\xc2\\xe4.\\t312874@gg.com'
更改为u'\\xebE\\xc2\\xe4.\\t312874@gg.com'
另外,您可以尝试执行'\\xebE\\xc2\\xe4.\\t312874@gg.com'.decode("utf-8")
,但它给出一个错误“无效的继续字节”,也许您的字符串不是有效的utf -8毕竟?
顺便说一句,提一下你运行的是python 2.x或3.x,有区别。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.