0

我已经尝试了很多方法,但我似乎无法弄清楚,但无论如何这就是我正在做的事情:

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))

最初我这样做是毫无疑问会起作用的,但我错了:

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

我不断得到:

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

我到底做错了什么?通常我会犯一些愚蠢的错误,但这次我看不到它......

谢谢 :)

4

1 回答 1

1

更新查询有 10 个%%s占位符,但 execute() 调用只有 9 个替换变量。最后WHERE id=%%s不能更换。如果您添加缺少的变量,它可能会起作用。

于 2013-04-26T11:31:55.163 回答