python - 错误 : 1318 Incorrect number of arguments for PROCEDURE | Flask

标签 python mysql stored-procedures flask

我收到此错误消息。它仅在 _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/

相关文章:

python - 使用 Python 匹配文件中的数字

mysql性能指标

python - NLTK 词干提取不通过简单的案例

python - Ubuntu + virtualenv = 一团糟? virtualenv 讨厌 dist-packages,想要 site-packages

用于 piglatin 脚本的 Python UDF 找不到 re 模块

mysql - MAMP MySql 中缺少 UTF-8 字符集

MySQL 全文索引与 Rails 2.3.2(迁移问题)

c# - 关于使用 XML 作为存储过程参数和返回类型的意见

sql-server - TSQL - 合并两个表

sql - 如何执行 SQL 游标转换