-1

I keep gettin this error with my SQL : Error reading data from MySQL table 400 Bad Request: The browser (or proxy) sent a request that this server could not understand. My SQL is correct, it works in the console but not in python file. I think the error is in params, because the code seems working and just after params, my print("done") doesn't print :) But I can't see it :/

this is my code ( btw I use the global variable g for my database and it works in my other functions) :

 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()
AdTCode
  • 25
  • 7
  • I think the issue could be in the in the second parameter because you have a $s in stead of a %s – enriqueojedalara Apr 28 '21 at 05:28
  • thank you, you're right about that error but it doesn't work neither :/ – AdTCode Apr 28 '21 at 05:32
  • What happens when you print formulaire.form? What is inside? Confirm all your keys exists on this MultiDict – enriqueojedalara Apr 28 '21 at 05:43
  • Thank you! That helped, i had one formulaire.form error because in the HTML i added "disabled", but once I removed it worked. The problem is that I need that specific input text disabled (I don't want the users to change the text inside it )because the text inside it is generated automatically with javascript. And I put that input field inside the form so I can use it in python with SQL, but now I can't use "disabled" . Is there a way to fix this problem? – AdTCode Apr 28 '21 at 05:56

1 Answers1

0

I see the issue is after VALUES you have:

VALUES (%s,$s ...

and should be:

VALUES (%s,%s ...
Luck
  • 21
  • 3
  • Just corrected it, but keep saying same error :/ – AdTCode Apr 28 '21 at 05:34
  • Then see https://stackoverflow.com/questions/48780324/flask-bad-request-the-browser-or-proxy-sent-a-request-that-this-server-could/48781606 I think you are trying to access to a key that does not exist in formulaire.form – Luck Apr 28 '21 at 05:41