Python ';并非所有参数都在字符串格式化期间转换';对于executemany()

Python ';并非所有参数都在字符串格式化期间转换';对于executemany(),python,mysql,Python,Mysql,我想通过insert命令将多个数据集插入MySQL表。为此,我定义了以下方法: def addRecords(self, records): """Add a list of shop -> filename entries into the records""" import pprint pprint.pprint(records) self.cursor.executemany(""" INSERT INTO foo_records (

我想通过insert命令将多个数据集插入MySQL表。为此,我定义了以下方法:

def addRecords(self, records):
    """Add a list of shop -> filename entries into the records"""
    import pprint
    pprint.pprint(records)
    self.cursor.executemany("""
        INSERT INTO foo_records ('shop_id', 'filename', 'missing_since', 'last_reported')
        VALUES (?, ?, NOW(), NOW())
        """, records)
当我执行此命令时,我得到了
TypeError:在字符串格式化过程中,调用
executemany
的行中没有转换所有参数

“shop_id”是mysql上的INT(11),“filename”定义为VARCHAR(60)

记录的内容如下所示:

[(1234, u'foo.csv'),
 (1234, u'bar.csv'),
 ..
 (1456, u'foobar.txt')]
我错过了什么


编辑:我在SQL上犯了一个愚蠢的错误。列名嵌入在
中。当我删除它们时,它使用的是
%s
,而不是

我认为问题在于问号。如果改用
%s
(如指定)会发生什么情况:


为此,我收到了
\u mysql\u异常。编程错误:(1064,“您的SQL语法有错误;请查看与您的mysql服务器版本对应的手册,以了解在“shop\u id”、“filename”、“missing\u since”、“last\u reported”值附近使用的正确语法(第1行437”)
因为店铺id应该是整数,而不是字符串。但是当我为商店id设置
%d
时,错误消息是
类型错误:%d格式:需要数字,而不是str
。我还试图找到一个元组,其中shop_id保存为字符串。然后我也使用
%d
。这也不起作用。MySQL提供了
convert()
函数()(例如
选择convert('1aa',INTEGER),convert('0x120',INTEGER),convert('10',INTEGER);
)。您可以将其添加到insert以将值转换为整数。
self.cursor.executemany("""
        INSERT INTO foo_records ('shop_id', 'filename', 'missing_since', 'last_reported')
        VALUES (%s, %s, NOW(), NOW())
        """, records)