Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将(unicode?)文本插入sqlite3数据库时出错_Python_Unicode_Sqlite - Fatal编程技术网

Python 将(unicode?)文本插入sqlite3数据库时出错

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

我创建了一个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.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的字符串。感谢您的帮助。