我收到此错误消息。它仅在 _query
具有单个字符时有效。其他明智的抛出和错误信息。我正在为 Flask 使用 MySQL 扩展。
{ error: "(1318, 'Incorrect number of arguments for PROCEDURE alexspider.SearchStore; expected 1, got 2')" }
MySQL 过程:
DELIMITER $$
CREATE PROCEDURE SearchStore(
IN Keyword VARCHAR(50))
BEGIN
SELECT *
FROM noones
WHERE name LIKE CONCAT('%', Keyword, '%');
END$$
DELIMITER ;
flask 应用程序.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 Incorrect number of arguments for PROCEDURE | Flask,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37183421/