我有一个问题 sql query don't work in flask

I have a problem with sql query don´t work in flask

我尝试 运行 该代码,但我对 sql 查询有问题,但如果 运行 mysql workbeck 中的查询有效

app.config['MYSQL_HOST'] = "localhost"
app.config['MYSQL_USER'] = "root"
app.config['MYSQL_PASSWORD'] = ""
app.config['MYSQL_DB'] = "inventario_bodega"
mysql = MySQL(app)

@app.route("/login", methods=["POST"])
def login():
    try:
        data = request.json
        user = data["user"]
        password = data["password"]
        cur = mysql.connection.cursor()
        #thats part don´t work
        cur.execute("SELECT * FROM usuarios WHERE usuario = %s", (user))

        data = cur.fetchone()
        cur.close()
        if(not (data == [])):
            if(data[6] == password):
                encoded_jwt = jwt.encode(
                    {'datos': data}, app.config['SECRET_KEY'], algorithm='HS256')
                return encoded_jwt, 200
            else:
                return "Usuario y/o Contraseña incorrecta", 401
        else:
            return "Usuario y/o Contraseña incorrecta", 401
    except:
        return "Error al iniciar sesion", 500

但不显示错误,只显示 500 错误

this is what appears to me in the terminal

cur.exectute() 想要一个元组或参数列表。看起来你正在尝试前者,这是 Python 中的边缘情况之一,其中逗号区分用于形成元组的括号或用于控制评估顺序的括号。

改变

cur.execute("SELECT * FROM usuarios WHERE usuario = %s", (user))

cur.execute("SELECT * FROM usuarios WHERE usuario = %s", (user,))