2017-07-19 39 views
0

我有一個csv文件,我正在加載,你可以看到下面鏈接以及我得到的錯誤輸出。我無法弄清楚爲什麼會出現這個錯誤。任何幫助表示讚賞。不會將csv數據存儲到mysql表中?

def url_store(): 
     run_urlcrazy() 
     url_file = open('url_csv') 
     csv_reader = csv.reader(url_file) 
     cursor = db.cursor() 
     for row in csv_reader: 
      cursor.execute("INSERT INTO scanresults(typotype,squatdomain, ip, id, domaincontact, mx, originaldomain, ipcontact) \ 
     VALUES (%s, %s, %s, %s, %s, %s, %s, %s)", str(row)) 

    db.commit() 
    cursor.close() 

Error Screenshot

CSV file

回答

1

查詢預計8個參數(由(%s, %s, %s, %s, %s, %s, %s, %s)表示),但是隻提供一個單一的參數,即str(row)

如果您確信row包含8個字符串值,你可以使用

cursor.execute("INSERT INTO scanresults(typotype,squatdomain, ip, id, domaincontact, mx, originaldomain, ipcontact) \ 
    VALUES (%s, %s, %s, %s, %s, %s, %s, %s)", *row) 

或只是

cursor.execute("INSERT INTO scanresults(typotype,squatdomain, ip, id, domaincontact, mx, originaldomain, ipcontact) \ 
    VALUES (%s, %s, %s, %s, %s, %s, %s, %s)", (row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7]))