简体   繁体   中英

Python sqlite3 Value Error

I have been getting this error and have stuck a few hours trying to understand what I am doing wrong. I have use this template for successfully importing into sqlite3 many many times in the past.

def TestImport():
   con = sqlite3.connect("test.db")
   con.execute("CREATE TABLE IF NOT EXISTS TestTable(ColA,ColB)")
   data=[('x','y')]
   stmt = "INSERT INTO TestTable VALUES(?,?)"
   con.execute(data,stmt)
   con.commit()
   con.close()

However this time I am getting this error:

ValueError: operation parameter must be str or unicode

here

con.execute(data,stmt)

它应该是

con.execute(stmt, data[0])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM