2017-07-23 2 views
0

Ich bin vor die Fehlermeldungpymsql + nicht genug Argumente für Formatstring + durch eine Liste

TypeError: not enough arguments for format string

Hier ist mein Code

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 

Voll Fehler Zurückverfolgungs:

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 

haben Sie irgendwelche Informationen?

Antwort

0

Die Daten sollten 7 Elemente enthalten (eins pro% s). Wahrscheinlich nicht. So

0

Ich habe ein paar txt-Dateien, die ich von

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() 

Last und dann durch Zip-Funktion merge, aber leider habe ich die oben genannte Fehlermeldung Insgesamt gibt es sieben Felder, die genau wie da erwartet " Executemany "? Da readlines() gibt eine Liste

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 

Ich bin wirklich ein bisschen Verzweiflung, mit der MySQL-Schnittstelle

Verwandte Themen