Passing a single argument to
cursor.execute(), or the “missing comma”
The asker is trying to execute SQL with a single placeholder and is passing the argument instead of a 1-tuple of arguments to execute. For example with the
stmt = "SELECT * FROM users WHERE username = %s" username = ('email@example.com') result = cursor.execute(stmt, username)
One way to fix is to add the missing comma in order to turn
username into a tuple:
username = ('firstname.lastname@example.org',)
Any sequence should do, so a list would work as well:
The relevant DB-API v2.0 link.
- Python MySQL Connector database query with %s fails
- psycopg2 how deal with TypeError: not all arguments converted during string formatting
- How to create a tuple with only one element
- Number of MySQL query parameters match arguments passed to execute, but Python raises "not all arguments converted"
- sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 74 supplied
- TypeError: 'int' object does not support indexing