MySQLdb: TypeError: %d format: a number is required, not str
I was getting this error message from MySQLdb:
TypeError: %d format: a number is required, not str
The error message was the result of this code:
1 | assert type(gateway_id) == int |
It turns out, execute converts all the arguments to SQL literal values. reference All %Xs should be %s and there shouldn’t be any quotes around them. MySQLdb takes care of the string escaping too.
Other Causes:
For those of you arriving here from a search and are not having problems with MySQL, the reason for this error is that a string was passed into a format where a number was expected:
1 | # throws the TypeError: |