python und mySQLdb Insert

Hallo ich bekomme bei dem Insert in python eine fehlermeldung weiss nicht wirklich viel damit anzufangen, es liegt wohl an der uebergabe der Variablen hat irgendwer schon erfahrung damit gemacht oder weiss wie ich die variablen angeben muss evtl eine Liste erstellen ?

Code:
[COLOR=#f9ee98]with [/COLOR][COLOR=#dad085]open[/COLOR]([COLOR=#008080]"temp_link.txt"[/COLOR]) [COLOR=#f9ee98]as [/COLOR]temp_link[COLOR=#cc7832], [/COLOR]\
     [COLOR=#dad085]open[/COLOR]([COLOR=#008080]"temp_LinkHash.txt"[/COLOR]) [COLOR=#f9ee98]as [/COLOR]temp_hash[COLOR=#cc7832], [/COLOR]\
     [COLOR=#dad085]open[/COLOR]([COLOR=#008080]"temp_nick.txt"[/COLOR]) [COLOR=#f9ee98]as [/COLOR]temp_nick[COLOR=#cc7832], [/COLOR]\
     [COLOR=#dad085]open[/COLOR]([COLOR=#008080]"temp_region.txt"[/COLOR]) [COLOR=#f9ee98]as [/COLOR]temp_region[COLOR=#cc7832], [/COLOR]\
     [COLOR=#dad085]open[/COLOR]([COLOR=#008080]"temp_imgLink.txt"[/COLOR]) [COLOR=#f9ee98]as [/COLOR]temp_imgLink[COLOR=#cda869]:
[/COLOR]tpm_link [COLOR=#cda869]= [/COLOR]temp_link.read().splitlines()
     tpm_hash [COLOR=#cda869]= [/COLOR]temp_hash.read().splitlines()
     tpm_nick [COLOR=#cda869]= [/COLOR]temp_nick.read().splitlines()
     tpm_region [COLOR=#cda869]= [/COLOR]temp_region.read().splitlines()
     tpm_imgLink [COLOR=#cda869]= [/COLOR]temp_imgLink.read().splitlines()
     item_id [COLOR=#cda869]= [/COLOR][COLOR=#f9ee98]None
[/COLOR][COLOR=#dad085]print[/COLOR]()

data [COLOR=#cda869]= [/COLOR][([COLOR=#008080]'item_id'[/COLOR][COLOR=#cc7832], [/COLOR][COLOR=#008080]'tpm_hash'[/COLOR][COLOR=#cc7832], [/COLOR][COLOR=#008080]'tpm_link'[/COLOR][COLOR=#cc7832], [/COLOR][COLOR=#008080]'tpm_nick'[/COLOR][COLOR=#cc7832], [/COLOR][COLOR=#008080]'tpm_region'[/COLOR][COLOR=#cc7832], [/COLOR][COLOR=#008080]'tpm_imgLink'[/COLOR])]

sql [COLOR=#cda869]= [/COLOR]([COLOR=#008080]""" INSERT INTO tbl_url_com (item_id, hash_url, link_url, name, stadt_ort, img_url) VALUES (%s, %s, %s, %s, %s, %s, %s) """[/COLOR])


cursor.executemany(sql[COLOR=#cc7832], [/COLOR]data)
conn.commit()
conn.close()

als fehlermeldung erhalte ich

Code:
Traceback (most recent call last):
  File "/home/unixben/Development/python/scrape/domain/mysqlsave.py", line 28, in <module>
    cursor.executemany(sql, data)
  File "/usr/local/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 281, in executemany
    self._get_db().encoding)
  File "/usr/local/lib/python2.7/dist-packages/MySQLdb/cursors.py", line 297, in _do_execute_many
    v = values % escape(next(args), conn)
TypeError: not enough arguments for format string

bin fuer jede hilfe Dankbar
 
Du hast 7 Mal %s im Formatstring, aber nur 6 Items in data. Es werden also 7 Strings erwartet und nicht nur 6.
 
so hab das ganze jetzt mal auf eine datei und liste beschränkt aber irgendwie erhalte ich immernoch den gleichen fehler

Code:
daten [COLOR=#cda869]= [/COLOR][COLOR=#dad085]list[/COLOR]()
file [COLOR=#cda869]= [/COLOR][COLOR=#dad085]open[/COLOR]([COLOR=#008080]"temp_data.txt"[/COLOR][COLOR=#cc7832],[/COLOR][COLOR=#008080]"r"[/COLOR])
[COLOR=#f9ee98]for [/COLOR]line [COLOR=#f9ee98]in [/COLOR]file[COLOR=#cda869]:
[/COLOR]daten.append(line.strip().split([COLOR=#008080]","[/COLOR]))
file.close()
cursor.execute([COLOR=#008080]"INSERT INTO tbl_domain_com (hash_url, link_url, name, stadt_ort, img_url) VALUES ('%s','%s','%s','%s','%s')" [/COLOR][COLOR=#cda869]% [/COLOR]daten)
conn.commit()
conn.close()


Code:
Traceback (most recent call last):
  File "/home/unixben/Development/python/scrape/domain/mysqlsave.py", line 29, in <module>
    cursor.execute("INSERT INTO tbl_domain_com (hash_url, link_url, name, stadt_ort, img_url) VALUES ('%s','%s','%s','%s','%s')" % daten)
TypeError: not enough arguments for format string
 
Und wie schauen die Testdaten denn aus?
Mal versucht über print/repr die Daten auszugeben?
Code:
print(daten)
repr(daten)
Sonst schaut das bei einer Liste in etwa so aus:
Code:
>>> "%s %s %s %s" % tuple([1,2,3,4])
'1 2 3 4'
 
Zurück
Oben