python - 类型错误 : execute() takes at most 3 arguments (11 given)

标签 python mysql mysql-python

我正在尝试使用 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/

相关文章:

python - tensorflow 中是否有与list.append()类似的函数?

mysql - 如何为仅包含 ibdata 和 *.ibd 文件的 MySQL InnoDB 表重新创建 FRM 文件?

php从base64字符串将blob插入mysql

python - 无法将查询结果分配给 python 变量

python : What's wrong with my code of multi processes inserting to MySQL?

Python 2D 插值

python web 套接字握手不起作用

Python Pandas 列按计数排序

php - 在mysql中插入和resort数据

python - MySQL-Python 代码将 `' 添加到数据库名称