【发布时间】:2021-07-21 10:54:03
【问题描述】:
我的 SQL 不断出现这个错误:
Error reading data from MySQL table 400 Bad Request: The browser (or proxy) sent a request that this server could not understand. 我的 SQL 是正确的,它在控制台中有效,但在 python 文件中无效。我认为错误在参数中,因为代码似乎在工作,并且在参数之后,我的 print("done") 没有打印:) 但我看不到它:/
这是我的代码(顺便说一句,我将全局变量 g 用于我的数据库,它适用于我的其他函数):
cursor = g.connection.cursor(dictionary=True)
requete = f""" insert into classicmodels.customers
( customerNumber,
customerName,
contactLastName,
contactFirstName,
phone,
addressLine1,
addressLine2,
city,
state,
postalCode,
country
) VALUES (%s,%s,%s, %s, %s , %s, %s, %s, %s, %s, %s)
"""
nouveau_id = self.obtenir_dernierCustomerNumber()["customerNumber"]
params = (nouveau_id, formulaire.form['nom'] + formulaire.form['prenom'],
formulaire.form['nom'], formulaire.form['prenom'],
formulaire.form['phone'], formulaire.form['adresseA'], formulaire.form['adresseB'],
formulaire.form['ville'], formulaire.form['etat'],
formulaire.form['codePostal'], formulaire.form['country'],)
print(params)
cursor.execute(requete, params)
g.connection.commit()
【问题讨论】:
-
我认为问题可能出在第二个参数中,因为您使用的是 $s 而不是 %s
-
谢谢你,你对那个错误是对的,但它也不起作用:/
-
打印 formulaire.form 时会发生什么?里面是什么?确认此 MultiDict 上存在您的所有密钥
-
谢谢!这有帮助,我有一个 formulaire.form 错误,因为在 HTML 中我添加了“禁用”,但是一旦我删除它就可以了。问题是我需要禁用特定的输入文本(我不希望用户更改其中的文本),因为其中的文本是使用 javascript 自动生成的。我把那个输入字段放在表单中,这样我就可以在 python 中使用它和 SQL,但现在我不能使用 "disabled" 。有没有办法解决这个问题?