批量插入给出了TypeError:格式字符串的参数不够

时间:2018-05-31 02:16:39

标签: python mysql-python python-2.x

我正试图在MySqlDB中保存一堆元组。

cursor = cnx.cursor()
query = """INSERT INTO `TableA`
            (`clientid`,
           `createddatetime`,
           `siteid`,...)
        VALUES(%s,%s,%s,...)"""

cursor.executemany(query, listTosave)

我的listTosave就像:

[('AS0001', '1170', '1', '1', 'Unknown', '442', '1', '2018-05-28 23:00:00', '2018-03-15 11:15:00', '2018-03-15 10:56:00', '2018-05-28 23:18:26', '2018-05-28 23:59:22', '15177.3184', '15185.7562', '8.4378', '1313.0547', '1313.6179', '0.5632', '0.0000', '0.0000', '0.0000', '0.0000', '0.0000', '0.0000', '24.6518', '24.6518', '15101.7062', '0.0', '0.0', '0.0', '24.6563'), (.....)]

执行时,我

    cursor.executemany(query , listTosave)
  File "/tmp/pymodules/pymysql/cursors.py", line 192, in executemany
  File "/tmp/pymodules/pymysql/cursors.py", line 208, in _do_execute_many
TypeError: not enough arguments for format string

我在这里做错了什么?

P.S:

  • 我的python版本是2.7.15。我在我的元组列表中传递了正确数量的参数
  • 如果我使用?而不是%s标志我得到以下错误 TypeError: not all arguments converted during string

在这里问了一个问题:

TypeError: not all arguments converted during string formatting Error in tuple python

0 个答案:

没有答案