我的查询在python瓶中如下所示
result = app._engine.execute ("select bookingid, DATE_FORMAT(bookingdate, '%Y-%m-%d'), DATE_FORMAT(pickupdate, '%Y-%m-%d'), consigneeid, fromcity from booking where consignerid = '{0}'".format(loginid))当我在MySQL工作台中运行并以yyyy dd格式返回日期时,此查询可以工作,但当我在python中运行该查询时,请获得以下错误
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/MySQLdb/cursors.py", line 187, in execute
query = query % tuple([db.literal(item) for item in args])TypeError: not enough arguments for format string它正在寻找更多的参数,尽管查询中的%用于格式化而不是传递参数。我确实试图寻找原因,但找不到一个好的原因,我在这里做错了什么?
发布于 2017-06-19 07:35:34
当对Python使用MySQL连接器时,您应该转义文字%,这是因为Python使用百分比符号(%)进行字符串格式设置。
试试这个:
result = app._engine.execute ("select bookingid, DATE_FORMAT(bookingdate, '%%Y-%%m-%%d'), DATE_FORMAT(pickupdate, '%%Y-%%m-%%d'), consigneeid, fromcity from booking where consignerid = '{0}'".format(loginid))https://stackoverflow.com/questions/44623134
复制相似问题