python - Psycopg2 execute tuple index out of range -


i new python , first programming language. first shot @ using sql psycopg2. "dumb" advice appreciated!

i not sure problem is. research tells me im feeding few or many arguments cursor.execute(insert... have tried number of different counts , can't seem working correctly. point of view cursor.execute(create... creates table 6 columns , passing 6 args it.

from lxml import html  # used parse xml import requests #used service api request  itemtypeid1 = 34 itemtypeid2 = 35 regionid = 10000002  webpage = requests.get('http://api.eve-central.com/api/marketstat?typeid=%i&typeid=%i&regionlimit=%i' % ( itemtypeid1, itemtypeid2, regionid))  if webpage.status_code == 200:     data = html.fromstring(webpage.content)     item in data.iter('type'):           buy_dict = {node.tag: node.text node in item.xpath("buy/*")}         sell_dict = {node.tag: node.text node in item.xpath("sell/*")}          #variables output         itemid = (item.get("id"))         buymin = buy_dict['min']         buymax = buy_dict['max']         buymedian = buy_dict['median']         buyvolume = buy_dict['volume']         buyaverage = buy_dict['avg']  #fail if api webpage unavaliable else:         print "webpage unavaliable"         webpage.raise_for_status()   #############################################################################   import psycopg2  connection = psycopg2.connect(database='evemarketdata', user='postgres', password='black3car')  #open cursor perform db operations cursor = connection.cursor()  #create new table cursor.execute("create table arkonor (itemid integer primary key, min integer, max integer, median integer, volume integer, average integer);")  #insert row data db table cursor.execute("""insert arkonor (typeid, min, max, median, volume, average)      values (%s, %s, %s, %s, %s, %s, %s, %s)""",      ('itemid', 'buymin', 'buymax', 'buymedian', 'buyvolume', 'buyaverage'))   #commits changes cursor #connection.commit() 

results in

 traceback (most recent call last):   file "e:\eve spreadsheets\python\postgreconnect.py", line 49, in <module>  ('itemid', 'buymin', 'buymax', 'buymedian', 'buyvolume', 'buyaverage'))  indexerror: tuple index out of range 

you have 8 parameters in query provided 6 fields in tuple. code should be:

#insert row data db table cursor.execute("""insert arkonor (typeid, min, max, median, volume, average)      values (%s, %s, %s, %s, %s, %s)""",      ('itemid', 'buymin', 'buymax', 'buymedian', 'buyvolume', 'buyaverage')) 

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -