Seite 1 von 1

pymsql + not enough arguments for format string ??

Verfasst: Sonntag 23. Juli 2017, 17:17
von Pythty
Hallo
ich habe ein paar textdatein mit inhalt die per executemany in die Datenbank eingefügt werden sollen, leider erhalte ich die meldung;
"not enough arguments for format string"

hier mal mein Code

Code: Alles auswählen

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 = "INSERT INTO table_e2e (hash_url, link_url, headline, snippet, rub_id, datum, time) VALUES (%s, %s, %s, %s, %s, %s, %s)"
    cur.executemany(sql_insert, data)
    db.commit()
else:
    pass


und hier mal die fehlermeldung

Code: Alles auswählen

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

weiß jemand woran es liegen kann ??

Re: pymsql + not enough arguments for format string ??

Verfasst: Sonntag 23. Juli 2017, 18:29
von Sirius3
@Pythty: woher kommen die sieben! Dateien? Wer erzeugt die? Und warum? Bei Einlesen machst Du schon einen Fehler. In der Datenbank sollten date und time nicht getrennt sein, sondern ein gemeinsames TIMESTAMP-Feld sein. Schau Dir mal an, was »data« enthält und was »executemany« braucht.