2017-03-11 175 views
-1

我查詢時完全轉化爲:錯誤在Python:不參數字符串格式化

z = request.session['username'] 
cursord.execute("delete from table where column = %s",z) 

得到錯誤不參數字符串格式化過程中完全轉化。

query = query % tuple([db.literal(item) for item in args]) TypeError: not all arguments converted during string formatting "GET /logout/ HTTP/1.1" 500 68562

如何解決這個問題?

+0

你可以編輯你的問題發佈完整的錯誤堆棧跟蹤,因爲它很容易調試。 –

+0

什麼是打印(z),z可能不是您期望的字符串 – putonspectacles

+0

z正在打印爲用戶名 – zinc

回答

0

你需要傳遞一個元組:如果你真的是使用Django,註銷有人以正確的方式從會話使用logout來看,由於詳細in the documentation

cursord.execute("delete from table where column = %s", (z,)) 

+0

我試過了,但是它給了編程錯誤。 ProgrammingError:(1064,「你的SQL語法錯誤;查看與你的MySQL服務器版本相對應的手冊,在第1行'table ='username''附近使用正確的語法」) – zinc

+0

這是另一個問題,用Python做。 –

+0

感謝Burhan,但爲什麼需要傳遞元組? – zinc