[英]TypeError: execute() takes from 2 to 3 positional arguments but 7 were given
I have the following code and it is throwing the TypeError: execute() takes from 2 to 3 positional arguments but 7 were given.我有以下代码,它抛出 TypeError:execute() 需要 2 到 3 个位置参数,但给出了 7 个。 I'm not sure if it's right but here it is:
我不确定它是否正确,但它是:
result_time = cur.execute("SELECT appointment_id FROM appointments WHERE appointment_time =%s", [appointment_time], "AND appointment_date =%s", [appointment_date], "AND doctor_id =%s", [actual_doctor_id.get('doctor_id')])
So I want a particular appointment_id when all requirements are met.因此,当满足所有要求时,我想要一个特定的约会 ID。
cursor.execute
takes the sql and a tuple of params - you gave the params singled-ly - hence you "overstuffed" it and get cursor.execute
接受 sql 和一个 params 元组 - 你单独给了 params - 因此你“过度填充”它并得到
TypeError: execute() takes from 2 to 3 positional arguments but 7 were given
类型错误:execute() 需要 2 到 3 个位置参数,但给出了 7 个
Change your code to contain 1 sql statement and one tuple with params:更改您的代码以包含 1 个 sql 语句和一个带参数的元组:
result_time = cur.execute(
"SELECT appointment_id FROM appointments WHERE appointment_time = %s AND appointment_date = %s AND doctor_id = %s",
( appointment_time, appointment_date, actual_doctor_id.get('doctor_id')) )
and it will work.它会起作用。
cursor.execute( sql, ( param1, param2, ... ) )
# this is all a tuple - hence the 2nd allowed param to execute.
See fe mysql-documentation or use http://bobby-tables.com/python as a quick reference.请参阅 fe mysql-documentation或使用http://bobby-tables.com/python作为快速参考。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.