Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

IndexError: list index out of range - while importing data (csv via python scripts)

By
kannu
on 9/3/14, 11:44 AM 2,903 views

Traceback (most recent call last):
  File "/opt/OpenERPWS/server/openerp/osv/osv.py", line 132, in wrapper
    return f(self, dbname, *args, **kwargs)
  File "/opt/OpenERPWS/server/openerp/osv/osv.py", line 199, in execute
    res = self.execute_cr(cr, uid, obj, method, *args, **kw)
  File "/opt/OpenERPWS/server/openerp/osv/osv.py", line 187, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/opt/OpenERPWS/addons/employee_system/department.py", line 27, in access_to_postgresql
    statement = "INSERT INTO product_template (name,description) VALUES ('"+str(row[1])+"','"+str(row[2])+"') RETURNING id"
IndexError: list index out of range
2014-09-03 15:40:10,931 18342 ERROR toc openerp.netsvc: list index out of range
Traceback (most recent call last):
  File "/opt/OpenERPWS/server/openerp/netsvc.py", line 296, in dispatch_rpc
    result = ExportService.getService(service_name).dispatch(method, params)
  File "/opt/OpenERPWS/server/openerp/service/web_services.py", line 626, in dispatch
    res = fn(db, uid, *params)
  File "/opt/OpenERPWS/server/openerp/osv/osv.py", line 190, in execute_kw
    return self.execute(db, uid, obj, method, *args, **kw or {})
  File "/opt/OpenERPWS/server/openerp/osv/osv.py", line 132, in wrapper
    return f(self, dbname, *args, **kwargs)
  File "/opt/OpenERPWS/server/openerp/osv/osv.py", line 199, in execute
    res = self.execute_cr(cr, uid, obj, method, *args, **kw)
  File "/opt/OpenERPWS/server/openerp/osv/osv.py", line 187, in execute_cr
    return getattr(object, method)(cr, uid, *args, **kw)
  File "/opt/OpenERPWS/addons/employee_system/department.py", line 27, in access_to_postgresql
    statement = "INSERT INTO product_template (name,description) VALUES ('"+str(row[1])+"','"+str(row[2])+"') RETURNING id"
IndexError: list index out of range?

 

 

 

 

CODE-

def access_to_postgresql(self, cr, uid, ids, context=None):
        import csv
        import psycopg2
        conn_string = "dbname= 'toc' user='openerp' password='sigma@123' host='localhost'"
        conn = psycopg2.connect(conn_string)
         
        cursor = conn.cursor()
         
        reader = csv.reader(open('prod.csv','rb'))
        for row in reader:
            print row[1]
             
            statement = "INSERT INTO product_template (name,description) VALUES ('"+str(row[1])+"','"+str(row[2])+"') RETURNING id"
                 
            cursor.execute(statement)
            conn.commit()
            templateid=cursor.fetchone()[0]
                    
            statement = "INSERT INTO product_product (product_tmpl_id,default_code,active,valuation) VALUES \
            (" + str(templateid) + ",'" + row[0] + "',True,'manual_periodic')"
                
            cursor.execute(statement)
            conn.commit()

csv fields- name,description

?

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 9/3/14, 11:44 AM
Seen: 2903 times
Last updated: 3/16/15, 8:10 AM