2013-04-26 48 views
0

我試過這個方法很多,我似乎無法弄清楚,但無論如何這裏是即時通訊做:的Python - MySQLdb的 - 更新行導致類型錯誤:沒有足夠的論據格式字符串

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 

什麼我究竟做錯了什麼?通常我做了一些愚蠢的錯誤,但我就是不明白這一次......

謝謝:)

+2

10次%% s,但execute()中只有9個變量 - >缺少最後一個id? – Gryphius 2013-04-26 11:25:31

+0

哇,這根本不是我所期望的,但它是非常感謝你,我完全忘記了'WHERE id = %% s'部分 – 2013-04-26 11:29:10

+0

作爲答案添加,隨時接受,如果它解決了您的問題;-) – Gryphius 2013-04-26 11:32:22

回答

1

更新查詢中有10個%%s佔位符,但execute()調用只有9替代變量。最後的WHERE id=%%s不能被替換。如果你添加缺少的變量,它可能會工作。

相關問題