pymsql + недостаточно аргументов для форматной строки + списком

Я сталкиваюсь с сообщением об ошибке

TypeError: not enough arguments for format string

Вот мой код

for data in zip(link_hash, link, headline, snippit, rubID, date, time):
    pass

if not sql_one_empty:
    sql_insert_hash = """ INSERT INTO ntv (link_hash, link, headline, snippit, rubID, date, time) VALUES (%s, %s, %s, %s, %s, %s, %s)"""

    cur.executemany(sql_insert_hash, data)
else:
    pass

Полная трассировка ошибок:

Traceback (most recent call last):
  File "/home/unixben/Development/python/mySQL_save.py", line 45, in <module>
    cur.executemany(sql_insert_hash, data)
  File "/usr/local/lib/python3.5/dist-packages/pymysql/cursors.py", line 193, in executemany
    self._get_db().encoding)
  File "/usr/local/lib/python3.5/dist-packages/pymysql/cursors.py", line 209, in _do_execute_many
    v = values % escape(next(args), conn)
TypeError: not enough arguments for format string

у кого-нибудь есть информация?

2 ответа

Данные должны содержать 7 элементов (по одному на каждый%s). Это, вероятно, нет.

Итак, у меня есть несколько текстовых файлов, которые я

with open("temp_link.txt") as temp_link, \
     open("temp_LinkHash.txt") as temp_hash, \
     open("temp_headline.txt") as temp_headline, \
     open("temp_snippet.txt") as temp_snippit, \
     open("temp_rubID.txt") as temp_rubID, \
     open("temp_date.txt") as temp_date, \
     open("temp_time.txt") as temp_time:
     link_url = temp_link.readlines()
     hash_url = temp_hash.readlines()
     headline = temp_headline.readlines()
     snippit = temp_snippit.readlines()
     rubID = temp_date.readlines()
     date = temp_time.readlines()
     time = temp_rubID.readlines()

загрузить и затем с помощью функции zip merge, но, к сожалению, я получаю вышеупомянутое сообщение об ошибке в целом, есть ли 7 полей, что именно так, как и ожидалось, потому что "executemany"? Потому что readlines () возвращает список

with open("temp_link.txt") as temp_link, \
     open("temp_LinkHash.txt") as temp_hash, \
     open("temp_headline.txt") as temp_headline, \
     open("temp_snippet.txt") as temp_snippit, \
     open("temp_rubID.txt") as temp_rubID, \
     open("temp_date.txt") as temp_date, \
     open("temp_time.txt") as temp_time:
     link_url = temp_link.readlines()
     hash_url = temp_hash.readlines()
     headline = temp_headline.readlines()
     snippit = temp_snippit.readlines()
     rubID = temp_date.readlines()
     date = temp_time.readlines()
     time = temp_rubID.readlines()


for data in zip(hash_url, link_url, headline, snippit, rubID, date, time):
    pass

print(data)


if not sql_one_empty:
    sql_insert_hash = " INSERT INTO ntv (hash_url, link_url, headline, snippet, rub_id, datum, time) VALUES (%s, %s, %s, %s, %s, %s, %s)"
    cur.executemany(sql_insert_hash, data)
    db.commit()
else:
    pass

Я действительно немного отчаялся, с интерфейсом MySQL

Другие вопросы по тегам