Rainer Schmitz
Rainer Schmitz

Reputation: 1

pymsql + not enough arguments for format string + by a list

I am facing the error message

TypeError: not enough arguments for format string

Here is my 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

Full error traceback:

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

have anybody any information ?

Upvotes: 0

Views: 1305

Answers (2)

Rainer Schmitz
Rainer Schmitz

Reputation: 1

So I have a few txt files which I by

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

load and then by zip function merge, but unfortunately I get the above error message altogether, are there 7 fields, which exactly as expected because "executemany"? Because readlines () returns a list

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

I am really a bit of despair, with the MySQL interface

Upvotes: 0

Yuval Ben-Arie
Yuval Ben-Arie

Reputation: 1290

Data should contain 7 elements (one per each %s). It probably does not.

Upvotes: 1

Related Questions