csv - Error loading log file data into mysql using cvs format and python -


i trying take data log file in cvs format, open log file , inserting row row mysql. getting error this:

error traceback (most recent call last): file "/users/alex/pycharmprojects/pa_reporting/padb_populate.py", line 26, in values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)', row) file "/users/alex/anaconda/lib/python2.7/site-packages/mysqldb/cursors.py", line 187, in execute query = query % tuple([db.literal(item) item in args]) typeerror: not arguments converted during string formatting.

import csv import mysqldb  mydb = mysqldb.connect(host='192.168.56.103',     user='user',     passwd='pass',     db='palogdb') cursor = mydb.cursor()  csv_data = csv.reader(file('/tmp/palog_demodata-100.csv')) row in csv_data:      cursor.execute('insert palogdb(receive_time,serial,type,subtype,col1,time_generated,src,dst,natsrc,natdst,rule,\   srcusr,dstusr,app,vsys1,from,to,inbound_if,outbound_if,logset,col2,sessionid,col3,repeatcnt,sourceport,natsport,natdport, \     flags,proto,action,bytes,bytes_sent,bytes_received,packets,start,elapsed,category,col4,seqno,actionflags,srcloc,dstloc,none, \     pkts_sent,pkts_received,session_end_reason) \     values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)', row) #close connection database. mydb.commit() cursor.close() 

is possible, don't have enough data in row %s's? maybe row interpreted 1 value, , first %s expanded? try *row expand vector values.

to debug, try build string passed execute other method, e.g.

sql_string = 'insert ... values ({}, {}, {})'.format(*row) 

and print it. if such error, can check, whether generated string looks reasonable...


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

c - Unrecognised emulation mode: elf_i386 on MinGW32 -