我知道有关于此错误的堆栈溢出有许多问题,但我尝试了很多解决方案,显然它们都失败了。Python 3 SQLite3 - 绑定数量不正确
这里有一个列表:
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
我试图在SQLite3数据库中存储用户名和密码(由PassLib - https://pythonhosted.org/passlib/创建)。这些分别存储在变量“targetusername”和“password”中。我的问题是,当我真正尝试这两个变量插入一个名为“密码”数据库的表中,给出了这样的错误:
Incorrect number of bindings supplied. The current statement uses 1, and there are 11 supplied.
这里是什么targetusername和密码将存储的例子:
targetusername = "user4884072"
password = "$5$rounds=535000$ySH31paWMjEDCUUY$jdrBVGsoYnSMkdVBtjCaxQy2f0g3MX1Wts4vSYz7m.4"
此行给出了错误:
c.executemany("INSERT INTO {tn} ({idf}, {cn}) VALUES(targetusername, %s" % str(password).\
format(tn="Passwords"))
已多次更改,试图解决这个问题(这显然是受了Python的商店变量引起的),除H ERE是它原是:
c.execute("INSERT OR IGNORE INTO {tn} ({idf}, {cn}) VALUES (targetusername, password)".\
format(tn="Passwords", idf="Username", cn="Password"))
尝试解决方案后出现同样的错误。 – user4884072
@ user4884072:真的吗?我用一个完整的工作示例更新了我的答案。尝试运行它。我还建议你用可以工作的代码更新你的问题(你的第一个例子导致'TypeError')并且证明问题。 – mhawke