TypeError: execute()最多接受3个参数(给定)

时间:2022-08-15 23:18:14

I am trying to create a SignUp page using Tornado, Anaconda, MySQLdb connector. So I have 8 fields in the form and my Signuphandler has the logic to insert the person's input into mysql database.

我正在尝试使用Tornado、Anaconda、MySQLdb连接器创建一个注册页面。因此,表单中有8个字段,而我的Signuphandler有逻辑将person的输入插入到mysql数据库中。

I searched and followed the documentation and other resources online and - I tried the following

我在网上搜索并跟踪了文档和其他资源,我尝试了以下方法。

Initially I was getting this error query = query % tuple([db.literal(item) for item in args]) TypeError: not enough arguments for format string for 1) and 2)

首先,我得到了这个错误查询=查询% tuple([db.literal(item)用于args])类型错误:没有足够的参数用于格式化字符串1和2)

1)

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)

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,)])

So I googled and removed (), Now I am getting TypeError: execute() takes at most 3 arguments (11 given) error

因此,我搜索并删除了(),现在我得到了TypeError: execute()最多接受3个参数(给定)错误。

3)

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)Followed this python 3 arguments 6 given error

4)遵循python 3的参数6给出错误。

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),)

What is going wrong here? Can someone pls help me..

这里出了什么问题?有人能帮我吗?

Thanks..

谢谢. .

1 个解决方案

#1


4  

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,))

If I count well you have 10 times '%s' and 9 arguments for them. Try to remove one '%s'

如果我数得很好,你有10倍的“%s”和9个参数。试着删除一个' '% 1 ! ' '

#1


4  

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,))

If I count well you have 10 times '%s' and 9 arguments for them. Try to remove one '%s'

如果我数得很好,你有10倍的“%s”和9个参数。试着删除一个' '% 1 ! ' '