I have several users in the database and all the ones with id < 10 work fine, but the ones with id > 10 no longer work. The error that I get in the console is:
Traceback (most recent call last):
File "C:\Flask\APP-POWERBY\env\Lib\site-packages\MySQLdb\cursors.py", line 201, in execute
query = query % args
^^^^^^^^^^^^
TypeError: not all arguments converted during bytes formatting
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Flask\APP-POWERBY\env\Lib\site-packages\flask\app.py", line 2213, in __call__
return self.wsgi_app(environ, start_response)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Flask\APP-POWERBY\env\Lib\site-packages\flask\app.py", line 2193, in wsgi_app
response = self.handle_exception(e)
^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Flask\APP-POWERBY\env\Lib\site-packages\flask\app.py", line 2190, in wsgi_app
response = self.full_dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Flask\APP-POWERBY\env\Lib\site-packages\flask\app.py", line 1486, in full_dispatch_request
rv = self.handle_user_exception(e)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Flask\APP-POWERBY\env\Lib\site-packages\flask\app.py", line 1484, in full_dispatch_request
rv = self.dispatch_request()
^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Flask\APP-POWERBY\env\Lib\site-packages\flask\app.py", line 1469, in dispatch_request
return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)
Something has to do with this def…
def obtener_report_por_id_user(db,id_user):
with db.connection.cursor() as cursor:
juegos = []
#print(type(id))
#print(id)
result = cursor.execute("SELECT id,name,report FROM reports_workspace WHERE id_user = %s", str(id_user))
juegos = cursor.fetchall()
#print(juegos)
return juegos
This is NOT a solution, this is a much much worse problem! Don’t ever do this.
Check the documentation for the execute() method. What is the intended way to pass arguments to the query? Have a look at it, and imagine what you would do if you had two or more arguments instead of just one.
Yes. Did you check the documentation? A few seconds with Google turned up this page, but you may have something else you’ve been reading. MySQLdb User’s Guide — MySQLdb 1.2.4b4 documentation What does it say about the correct way to pass arguments?
Do you see a difference? (max_price,) works and str(id_user) doesn’t. If you don’t see a difference, read the documentation some more. I don’t think there’s anything more I can say to make this clearer. There is a highly significant difference here and you MUST see it or your databasing work will forever fail.
Excellent With a bit of thought, you can probably understand exactly why your original code failed once you hit a second digit. Or don’t worry about it, and just make the version with the tuple.