我正在尝试使用 Tornado、Anaconda、MySQLdb 连接器创建一个注册页面。 所以我的表单中有 8 个字段,我的 Signuphandler 具有将人员的输入插入 mysql 数据库的逻辑。
我在线搜索并遵循了文档和其他资源,并且 - 我尝试了以下方法
最初,我收到此错误 query = query % tuple([db.literal(item) for item in args]) TypeError: 对于 1) 和 2)<,格式字符串的参数不足
1)
cursor.execute("INSERT INTO user_table (firstName, lastName, a, b, c, d, e, f, g) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",(firstname, lastname, a, b, c, d, e, f, g,))
2)
cursor.execute("INSERT INTO user_table (firstName, lastName, a, b, c, d, e, f, g) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", [(firstname, lastname, a, b, c, d, e, f, g,)])
所以我用谷歌搜索并删除了 (),现在我收到 TypeError:execute() 最多需要 3 个参数(给定 11 个) 错误
3)
cursor.execute("INSERT INTO user_table (firstName, lastName, a, b, c, d, e, f, g) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", firstname, lastname, a, b, c, d, e, f, g,)
4)关注了这个python 3 arguments 6 given error
cursor.execute("INSERT INTO user_table (firstName, lastName, a, b, c, d, e, f, g) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", str(firstname), str(lastname), str(a), str(b), str(c), str(d), str(e), str(f), str(g),)
这里出了什么问题?有人可以帮助我吗..
谢谢..
最佳答案
cursor.execute(
"""INSERT INTO user_table
(firstName, lastName,
a, b, c, d, e, f, g)
VALUES
(%s, %s,
%s, %s, %s, %s,
%s, %s, %s, %s)""",
(firstname, lastname,
a, b, c, d,
e, f, g,))
如果我算得好的话,你有 10 个 '%s' 和 9 个参数。尝试删除一个“%s”
关于python - 类型错误 : execute() takes at most 3 arguments (11 given),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26793728/