Python sqlite TypeError: not all arguments converted during string formatting

juni 19, 2010

I just spent half an hour trying to get python to insert a bunch of strings into my sqlite db and I kept getting this typeerror. So I started my google fu and got to a bunch of unsolved forum posts.

I found the solution myself. You see, I had been doing this:

self.db.execute(‘INSERT INTO bookmarks(a,b,c) VALUES(?, ?, ?)’%(a,b,c))

(with correct placeholders for sqlite3: ‘?’), when I should have sent the tuple as a second argument to the execute function:

self.db.execute(‘INSERT INTO bookmarks(a,b,c) VALUES(?, ?, ?)’, (a,b,c))

So stupid. Might help someone in the future.

Lämna en kommentar

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Logga ut / Ändra )

Twitter-bild

You are commenting using your Twitter account. Logga ut / Ändra )

Facebook-foto

You are commenting using your Facebook account. Logga ut / Ändra )

Ansluter till %s

Follow

Get every new post delivered to your Inbox.