Python MySQLdb TypeError:并非在字符串格式化期间转换所有参数
运行此脚本时:
#! /usr/bin/env pythonimport MySQLdb as mdbimport sys class Test: def check(self, search): try: con = mdb.connect('localhost', 'root', 'password', 'recordsdb'); cur = con.cursor() cur.execute( "SELECT * FROM records WHERE email LIKE '%s'", search ) ver = cur.fetchone() print "Output : %s " % ver except mdb.Error, e: print "Error %d: %s" % (e.args[0],e.args[1]) sys.exit(1) finally: if con: con.close()test = Test()test.check("test")
我得到一个错误:
./lookup Traceback (most recent call last): File "./lookup", line 27, in <module> test.check("test") File "./lookup", line 11, in creep cur.execute( "SELECT * FROM records WHERE email LIKE '%s'", search ) File "/usr/local/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 187, in execute query = query % tuple([db.literal(item) for item in args])TypeError: not all arguments converted during string formatting
我不明白为什么。我正在尝试进行参数化查询,但这只不过是一种痛苦。我对Python有些新意,所以这可能是一个明显的问题。
慕勒3428872
拉丁的传说
相关分类