lundi 5 octobre 2015

Python 3 SQLite3 - Incorrect number of bindings

I understand there are MANY questions on Stack Overflow about this error but I have tried MANY solutions and obviously they have all failed.

Here's a list:

sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 74 supplied

SQLite parameter substitution problem

sqlite3.ProgrammingError: Incorrect number of bindings supplied

Reading from database with SQLite and Python: Incorrect number of binding supplied

SQLite Python Insert - Incorrect Number of Bindings Supplied

I am trying to store a username and hashed password (created by PassLib - http://ift.tt/1L1r0nT ) in a SQLite3 database. These are stored in the variables "targetusername" and "password" respectively. My problem is that when I actually try to insert these 2 variables into a table of a database called "Passwords", it gives this error:

Incorrect number of bindings supplied. The current statement uses 1, and there are 11 supplied.

Here's an example of what targetusername and password would store:

targetusername = "user4884072"
password = "$5$rounds=535000$ySH31paWMjEDCUUY$jdrBVGsoYnSMkdVBtjCaxQy2f0g3MX1Wts4vSYz7m.4"

This line gives the error:

c.executemany("INSERT INTO {tn} ({idf}, {cn}) VALUES(targetusername, %s" % str(password).\
format(tn="Passwords"))

It has been changed multiple times to try and fix the issue (which apparently is caused by how Python stores variables), but here is what it was originally:

c.execute("INSERT OR IGNORE INTO {tn} ({idf}, {cn}) VALUES (targetusername, password)".\
format(tn="Passwords", idf="Username", cn="Password"))

Aucun commentaire:

Enregistrer un commentaire