首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >MySQL Asterisk AGI - ValueError:无法处理参数

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

Stack Overflow用户
提问于 2020-03-24 05:26:12
回答 1查看 150关注 0票数 0

所以我已经对这个问题进行了一分钟的故障排除,奇怪的是它似乎在一个独立的Python脚本中运行得很好,但是当我被移动到一个星号AGI时,我得到了以下错误:

代码语言:javascript
复制
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")

下面是抛出此错误的相关数据。

代码语言:javascript
复制
#!/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变量的问题,因为它不是字符串,最终的解决方案是更改变量在查询中的包含方式,请参阅下面的示例,以获得解决方案

代码语言:javascript
复制
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)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-03-24 18:30:28

cursor.execute接受字符串,而不是参数。

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

变量res根本不是字符串。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60821759

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档