python execute传参_python-TypeError:execute()需要2到3个位置参数,但是给出了7个

我有以下代码,并抛出TypeError:execute()接受2到3个位置参数,但给出了7个.我不确定是否正确,但是这里是:

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

因此,当满足所有要求时,我想要一个特定的约会ID.

解决方法:

cursor.execute接受sql和一个参数元组-您单次给这些参数-因此您“塞满了”它并得到

TypeError: execute() takes from 2 to 3 positional arguments but 7 were given

更改您的代码包含1个sql语句和一个带params的元组:

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

它会工作.

cursor.execute( slq, ( param1, param2, ... ) )

# this is all a tuple - hence the 2nd allowed param to execute.

标签:select,where,python,mysql

来源: https://codeday.me/bug/20191211/2105416.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值