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.
- TypeError: 'int' object does not support indexing
- sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 74 supplied
- Number of MySQL query parameters match arguments passed to execute, but Python raises "not all arguments converted"
- How to create a tuple with only one element
- psycopg2 how deal with TypeError: not all arguments converted during string formatting
- Python MySQL Connector database query with %s fails