我正在尝试使用mysql在Python中进行简单查询,但出现此错误,并且我不知道为什么会有此错误:
ValueError: Could not process parameters
我在做什么是这样的:
mycursor = mydb.cursor()
sql="SELECT pathFile FROM googlesearch where tweetid=%d LIMIT 1"
print(lastid)
print(sql)
mycursor.execute(sql,(lastid),)
mydb.commit()
myresult = mycursor.fetchall()
print(myresult)
为什么我有此错误?如您所见,这是一个简单的查询。谢谢
在行中添加逗号: mycursor.execute(sql,(lastid),)
(lastid,)
是一个元组,但(lastid)
不是。
因此请mycursor.execute(sql,(lastid,),)
改用(注意后面的逗号lastid
)
有关更多参考,请在此处查看文档:
它说:
注意:在Python中,包含单个值的元组必须包含逗号。例如,('abc',)被评估为标量,而('abc',)被评估为元组。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句