I am at a loss as to why this isn't working properly:<br><br>#!/usr/bin/python<br><br>import MySQLdb<br>import csv<br>import sys<br><br>try:<br> db = MySQLdb.connect (host = "localhost",user = "root",passwd = "########",db = "stats")<br>
except MySQLdb.Error, e:<br> print "Error %d: %s" % (e.args[0], e.args[1])<br> sys.exit (1)<br><br>co = db.cursor()<br>csv_data = csv.reader(file('output.txt','r'))<br>headers = csv_data.next()<br>
row = csv_data.next()<br>prefix = row[:17]<br>for i in range(17, len(row),8):<br> next = prefix + row[i:i+8]<br> print next<br>co.execute("""<br> INSERT INTO stats(Hostname, Time, Arch, PhysicalCPU, Count, Running, Blocked, Paused, Shutdown, Shutoff, Crashed, Active, Inactive, PCPU, TotalMemory, Totalguestmemory, TotalCPUtime, DomainID, Domainname, CPUTime, PGCPU, RDRQ, WRRQ, RXBY, TXBY)<br>
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");<br> """, row)<br>co.close()<br>db.commit()<br>db.close()<br><br>It pulls all of the data correctly and it is the correct of items that it is grabbing. I get this traceback:<br>
<br>Traceback (most recent call last):<br> File "./loadcsv.py", line 21, in ?<br> co.execute("""<br> File "/usr/lib64/python2.4/site-packages/MySQLdb/cursors.py", line 148, in execute<br>
query = query % db.literal(args)<br>TypeError: not all arguments converted during string formatting<br><br>If I have it print out the next variable...the data is correct that it is pulling out...<br><br>['<a href="http://test.test.net">test.test.net</a>', '15:33:59', 'x86_64', '8', '9', '1', '4', '0', '0', '0', '0', '5', '4', '0.0', '12495360', '818688', '0', '1', 'beta', '0.', '0.', '', '', '', '']<br>
<br>Maybe fresh eyes could pull out my mistake?<br><br>Thanks again for everything!<br>