[英]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.