所以我已经对这个问题进行了一分钟的故障排除,奇怪的是它似乎在一个独立的Python脚本中运行得很好,但是当我被移动到一个星号AGI时,我得到了以下错误:
cursor.execute(query, (res))
File "/usr/local/lib/python2.7/dist-packages/mysql/connector/cursor_cext.py", line 248, in execute
prepared = self._cnx.prepare_for_mysql(params)
File "/usr/local/lib/python2.7/dist-packages/mysql/connector/connection_cext.py", line 615, in prepare_for_mysql
raise ValueError("Could not process parameters")下面是抛出此错误的相关数据。
#!/usr/bin/env python
import sys
from asterisk.agi import *
from os import system
import subprocess
import time
import mysql.connector
import md5
agi = AGI()
agi.verbose("python agi started")
callerId = agi.env['agi_callerid']
agi.verbose("call from %s" % callerId)
res=agi.get_variable("res")
agi.verbose("want %s br" %res)
cnx = mysql.connector.connect(user='user',password='sanitized',host='127.0.0.1',database='rental')
cursor = cnx.cursor(buffered=True)
query = ("select active,address,rent,deposit,phone,pets_allow,smoker_allow,section_8,garage,attached_garage,fenced_yard,carport,shed,patio,deck,basement,garden_area,off_street,on_street,walkin_shower,double_lavs,back_porch,front_porch,cha,ac,fireplace,central_heat,stove,dish_washer,microwave,refrigerator,washer,dryer,washer_hu,dryer_hu,garbage_dispsal,water,trash_service,gas,electric,barn,wall_furnace from activelisting where active=1 and number_br=3")
query = ("select active,address,rent,deposit,phone,calldialog,id from activelisting where active=1 and number_br=3 order by id")
cursor.execute(query, (res))
cursor.close()
cnx.close()注意:从技术上讲,number_br=3应该是number_br=%s,但为了排除故障,我将其替换为静态变量。整个脚本都可以在旧版本的CentOS上运行,我正在尝试让它在Debian Server上运行。
编辑:正如arheops适当指出的那样,此查询存在res变量的问题,因为它不是字符串,最终的解决方案是更改变量在查询中的包含方式,请参阅下面的示例,以获得解决方案
query = ("select active,address,rent,deposit,phone,pets_allow,smoker_allow,section_8,garage,attached_garage,fenced_yard,carport,shed,patio,deck,basement,garden_area,of$
query = ("select active,address,rent,deposit,phone,calldialog,id from activelisting where active=1 and number_br={} order by id".format(res))
cursor.execute(query)发布于 2020-03-24 18:30:28
cursor.execute接受字符串,而不是参数。
https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlcursor-execute.html
变量res根本不是字符串。
https://stackoverflow.com/questions/60821759
复制相似问题