我收到这个错误信息。只有当_query
只有一个字符时,它才起作用。其他明智的抛出和错误消息。我正在使用MySQL Flask扩展。
{
错误:“(1318,'过程alexspider.SearchStore的参数数目不正确;应为1,得到2')”
}
MySQL过程:
DELIMITER $$
CREATE PROCEDURE SearchStore(
IN Keyword VARCHAR(50))
BEGIN
SELECT *
FROM noones
WHERE name LIKE CONCAT('%', Keyword, '%');
END$$
DELIMITER ;
烧瓶app.py
@app.route('/search', methods=['POST'])
def search():
try:
# Read the posted values from the UI
_query = request.form['query']
# Validationg the search Quoey
if _query:
conn = mysql.connect()
cursor = conn.cursor()
cursor.callproc('SearchStore', _query)
stores = cursor.fetchall()
if len(stores) > 0:
stores_dict = []
for store in stores:
store_dict ={
'name': store[2],
'url': store[3],
'cashback': store[4]}
stores_dict.append(store_dict)
return json.dumps(stores_dict)
else:
return render_template('error.hml', error = 'This is error message')
except Exception as e:
return json.dumps({'error': str(e)})
finally:
cursor.close()
conn.close()
最佳答案
在这条线上,
cursor.callproc('SearchStore', _query)
必须将参数作为列表传递。
这样地,
cursor.callproc('SearchStore', [_query,])
关于python - 错误:1318的参数数目不正确 flask ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37183421/