2015-05-28 26 views
1

我写了下面的程序写入到一个sqlite3的表:PythonGTK - 无法写入特殊字符到数据库

https://www.adrive.com/public/sJZKt3/program.py

它正常工作,试图挽救语言的特定字符,例如时除外:

AA,SS,C

当试图插入表中我得到以下错误消息:

SQL Error

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.

我该如何解决这个问题?

+0

我可以自动改变字符串unicode字符串?我想添加# - * - 编码:utf-8 - * - 会做的伎俩... – royskatt

+0

在python2你必须解码字符串。请参阅[Unicode HOWTO](https://docs.python.org/2/howto/unicode.html)和[参考](https://docs.python.org/2/library/stdtypes.html#str .decode)获取信息。否则,你可以切换到默认使用unicode字符串的python3。 – elya5

回答

1

改变文本为Unicode,所以你可以插入

text = "äöü" 
text = text.decode("utf8") 
+0

这是在python3吗?因为在python2我得到这个错误:UnicodeDecodeError:'utf8'编解码器无法解码位置0字节0xe4:无效继续字节 – mululu