Ganesh Pandey Ganesh Pandey - 6 months ago 55
SQL Question

error: 1318 Incorrect number of arguments for PROCEDURE | Flask

I am getting this error message. It only works when

_query
has single character. Other wise throws and error message. I am using MySQL extension for Flask.


{
error: "(1318, 'Incorrect number of arguments for PROCEDURE alexspider.SearchStore; expected 1, got 2')"
}


MySQL Procedure:

DELIMITER $$
CREATE PROCEDURE SearchStore(
IN Keyword VARCHAR(50))
BEGIN
SELECT *
FROM noones
WHERE name LIKE CONCAT('%', Keyword, '%');
END$$
DELIMITER ;





Flask 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()

Answer

In this line,

cursor.callproc('SearchStore', _query)

you must pass the argument as list. Like this,

cursor.callproc('SearchStore', [_query,])