How to fix: TypeError: not all arguments converted during string formatting in Python MySQLdb

If you encounter something similar to the following:

Traceback (most recent call last):
  File "scotia.failed.email.py", line 13, in <module>
    cursor.execute (' select * from fail f where f.emailid= (%s) ', (emailid))
  File "/usr/local/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 187, in execute
    query = query % tuple([db.literal(item) for item in args])
TypeError: not all arguments converted during string formatting:
#Instead of: 
cursor.execute (' select * from fail f where f.emailid= (%s) ', (emailid))
#Use:
cursor.execute (' select * from fail f where f.emailid= (%s) ', [emailid])
#Another example:
count=cursor.execute (' select * from fail f join contacts c on f.contactid=c.contactid  where f.emailid= (%s) and c.email = (%s)  ', [emailid,email])
print count

Popular posts from this blog

How to delete / clear queue of PowerMTA