Python 将(unicode?)文本插入sqlite3数据库时出错
我创建了一个sqlite3数据库,其中填充了db2数据库中的数据。运行以下操作时,我收到一个错误:Python 将(unicode?)文本插入sqlite3数据库时出错,python,unicode,sqlite,Python,Unicode,Sqlite,我创建了一个sqlite3数据库,其中填充了db2数据库中的数据。运行以下操作时,我收到一个错误: for row in db2_connection.execute(query): sqlite3_connection.execute("INSERT INTO MY_TABLE VALUES (?, ?, ?)", row) 以下是错误: File "example.py", line 72, in load_micr_db sqlite3_connection.execut
for row in db2_connection.execute(query):
sqlite3_connection.execute("INSERT INTO MY_TABLE VALUES (?, ?, ?)", row)
以下是错误:
File "example.py", line 72, in load_micr_db
sqlite3_connection.execute("INSERT INTO MY_TABLE VALUES (?, ?, ?)", row)
sqlite3.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.
这听起来是个很好的建议,但我不知道该怎么做。如何“将应用程序切换到Unicode字符串”
我正在使用Python2.6,
pyodbc
查询DB29,sqlite3
使用前缀为u
的字符串文本
print u'I am a Unicode string.'
你能把它打开吗?我切换了第二行(从上面的示例切换到
sqlite3_connection.execute(u“INSERT INTO my_TABLE VALUES(?,,?)”,row)
仍然收到相同的错误。也许我误解了您的答案?行
中的元素如果是字符串,也必须是unicode
。我的db2源代码返回需要使用“latin-1”解码为unicode的字符串。感谢您的帮助。