我的數據庫中有一條未執行的更新語句。據我所知,它在語法上是正確的。我用this app來驗證語法。 except
塊是所有正在執行,我不明白爲什麼。未能在Python CGI中執行的SQL語句
下面是代碼:
for res_posts in list_of_response_ids:
temp_str = res_posts[0] # first element of res_posts tuple is string
temp_str += ":" + str(output[0])
try:
sql = "UPDATE POST SET res_post_id = %s WHERE post_id = %d;" % (str(temp_str), int(res_posts[1]))
cursor.execute(sql)
except:
print "uh oh"
我可以發佈更多的代碼,如果這是沒有足夠的信息。
編輯:繼雅各的建議,我用raise
並得到了以下錯誤:
Traceback (most recent call last):
File "post.cgi", line 93, in <module>
cursor.execute(sql)
File "/usr/lib64/python2.6/site-packages/MySQLdb/cursors.py", line 173, in execute
self.errorhandler(self, exc, value)
File "/usr/lib64/python2.6/site-packages/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':37 WHERE post_id = 8' at line 1")
太謝謝你了!
在打印普通的消息,除了塊需要扔掉由蟒蛇提供的異常詳細信息。我建議在打印語句後在行上添加'raise',以便可以看到完整的堆棧跟蹤。如果您需要幫助解釋此跟蹤的含義,請將其粘貼到此處。 – JacobIRR
我已將輸出添加到我的帖子中。任何想法有什麼問題的語法? – Azhraam