简体   繁体   English

MySQL Asterisk AGI - ValueError:无法处理参数

[英]MySQL Asterisk AGI - ValueError: Could not process parameters

So I've been troubleshooting this one for a minute, what's weird is that it seems to run just fine in a stand alone Python script, but when being moved to an asterisk AGI I get the below error:所以我一直在解决这个问题,奇怪的是它似乎在独立的 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")

Below is the data in question that was ran that threw this error.以下是运行时引发此错误的相关数据。

#!/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()

Note: number_br=3, should technically be number_br=%s but for the sake of troubleshooting I substituted in a static variable.注意:number_br=3,技术上应该是number_br=%s,但为了故障排除,我用一个静态变量代替。 This whole script worked on an older version of CentOS and I'm attempting to get it all working on a Debian Server.整个脚本在旧版本的 CentOS 上运行,我正试图让它在 Debian 服务器上运行。

EDIT: As arheops appropriately noted, this query was having issues with the res variable, as it was not a string, the resolution was ultimately to change how the variable was included in the query, see below for an example that brought about the solution编辑:正如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)

cursor.execute accepting string, not touple as param. cursor.execute 接受字符串,而不是作为参数的元组。

https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlcursor-execute.html https://dev.mysql.com/doc/connector-python/en/connector-python-api-mysqlcursor-execute.html

Variable res is not string at all.变量 res 根本不是字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM