2017-03-11 164 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