我尝试运行该代码,但我的 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 错误