0

i wanted to insert new data into porstgresql using odooRPc i am having error like below RPCError: dictionary update sequence element #0 has length 1; 2 is required

my python script code is :

 def POST(self):
    data = []
    web.header('Access-Control-Allow-Origin',      '*')
    web.header('Access-Control-Allow-Credentials', 'true')
    web.header('Content-Type', 'application/json')

    auth = web.input()
    print("auth")
    print(auth)

    name=auth['username']
    pwd=auth['password']
    city=auth['city']
    eml=auth['eml']
    mobile=auth['phone']
    state_id=auth['state']
    country_id=auth['country']
    # print(type(auth['country']))
    # country_id=auth.get('Country').get('id')
    # country_id=auth['country'].get('id')
    # print(country_id)
    # state_id=auth['state']
    # print(state_id)

    odoo = odoorpc.ODOO('field.holisticbs.com',port=8069)
    odoo.login('field.holisticbs.com','info@holisticbs.com','admin')

    # Customer = odoo.execute_kw('res.partner','create',{'name':name,' email':eml,'mobile':mobile,' country_id':country_id,'state_id':state_id})
    Customer = odoo.execute_kw('res.partner','create',{'name':name,' email':eml,'mobile':mobile})
    print(Customer)
    # Users = odoo.env['res.partner']
    # user = Users.browse([int(idu)])
    # print(user)
    # Customer = odoo.execute_kw('res.user','create',{'login':eml,' password':pwd})

     return json.dumps(Customer)

1 Answers1

0

I have made my comments as below , kindly request you to find it as below it will help in your case:

Well there are many RPC Library (Python) for connecting with the API of Odoo/OpenERP:

  1. xmlrpclib
  2. odoorpc
  3. erppeek
  4. oerplib
  5. openerplib..

In Your case You have chose the odoorpc. Here is the code snippet for using it odoorpc:

import odoorpc
import json

domain ='localhost'         #the domain
port=8069                   #the active port
username = 'username'       #the user name
password = 'password'       #the user password 
dbname = 'database_name'    #the database

#Validate the credentials 
odoo = odoorpc.ODOO(domain, port=port)
odoo.login(dbname, username, password)

#Login User details
user = odoo.env.user 
print(user.name)            # user name
print(user.company_id.name) # user company name

#Create a partner
user_data = odoo.execute('res.partner', 'create',
   {'name':"PRAKASH",'
    email':" prakashsharmacs24@gmail.com",
     'mobile':"7859884833"})
print(user_data)

But i have also find you are using the method execute_kw so please use xmlrpclib if you want to use method execute_kw

Here is the code snippet for using it xmlrpclib:

import xmlrpclib

domain ='localhost'         #the domain
port=8069                   #the active port
username = 'username'       #the user name
password = 'password'       #the user password 
dbname = 'database_name'    #the database
#Validate the credentials 

url='http://{domain}:{port}'.format(domain=domain,port=port)
login_url='{url}/xmlrpc/2/common'.format(url=url)
sock_common = xmlrpclib.ServerProxy(login_url)
uid = sock_common.login(dbname, username, password)
print sock_common.version()
print uid

models = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format(url))
#Validate the access rights 
print models.execute_kw(dbname, uid, password,
'res.partner', 'check_access_rights',
['read'], {'raise_exception': False})

#Execute the query  
print models.execute_kw(dbname, uid, password,
'res.partner', 'search',
[[['is_company', '=', True], ['customer', '=', True]]])

You can also refer this Link for knowing the difference between the RPC library

I hope this will help you ..

Community
  • 1
  • 1
Prakash Kumar
  • 2,554
  • 2
  • 18
  • 28