Wichid Nixin
Wichid Nixin

Reputation: 285

Python - MySQLdb - Updating row causes TypeError: not enough arguments for format string

I've tried this many ways and I cant seem to figure it out but anyway here is what im doing:

threadupdatequery = "UPDATE %s SET topic_name=%%s, subject_name=%%s, poster_name=%%s, time=%%s, image=%%s, replies=%%s, id=%%s, keywords=%%s, text=%%s WHERE id=%%s" % ('Threads')
...
(topic, subject, name, time, image, replies, ID, kw, body) = self.tframe.Get()
cur.execute(threadupdatequery, (topic, subject, name, time, image, replies, ID, kw, body))

Originally I did this which I had no doubt would work but I was wrong:

cur.execute(threadupdatequery, self.tframe.Get())

I keep getting:

File "C:\Python27\Work\SiteEditor.py", line 216, in UpdateThread
cur.execute(threadupdatequery, (topic, subject, name, time, image, replies, ID, kw, body))
File "C:\Python27-32Bit\lib\site-packages\MySQLdb\cursors.py", line 184, in execute
query = query % db.literal(args)
TypeError: not enough arguments for format string

What exactly am I doing wrong? Usually I make some silly mistake but I just don't see it this time...

Thanks :)

Upvotes: 0

Views: 1093

Answers (1)

Gryphius
Gryphius

Reputation: 78886

the update query has 10 %%s placeholders, but the execute() call has only 9 replacement variables. the last WHERE id=%%s can not be replaced. if you add the missing variable it will probably work.

Upvotes: 1

Related Questions