RPCError: dictionary update sequence element #0 has length 1; 2 is required on python

RPCError: dictionary update sequence element #0 has length 1; 2 is required on python

我想使用 odooRPc 将新数据插入 porstgresql 我遇到如下错误 RPCError:字典更新序列元素#0 的长度为 1; 2 是必需的

我的 python 脚本代码是:

 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)

我的评论如下,请您在下方找到它,这将对您的情况有所帮助:

好吧,有许多 RPC 库 (Python) 用于连接 Odoo/OpenERP 的 API:

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

在您的情况下,您选择了 odoorpc。 这是使用它的代码片段 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)

但是我也发现你在使用方法execute_kw所以如果你想使用方法execute_kw请使用xmlrpclib

这是使用它的代码片段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

希望对您有所帮助..