让SQL工作的正确方法是什么?

2024-04-18 21:17:09 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在用我的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文件中不工作。我认为错误在params中,因为代码似乎正在运行,就在params之后,我的打印(“完成”)没有打印:),但我看不到:/

这是我的代码(顺便说一句,我在数据库中使用全局变量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()

Tags: 代码formidsql错误phoneparamsconnection