2016-04-15 147 views
0

我想插入新的數據到porstgresql使用odooRPc我有像下面的錯誤 RPCError:字典更新序列元素#0具有長度1; 2需要RPCError:字典更新序列元素#0長度爲1; 2是必需的python

我的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','[email protected]','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) 
+0

有你是第一個嘗試檢查連接: 用戶= odoo.env.user 打印(user.name),印刷(user.company_id.name ),它工作嗎? – prakash

+0

是它的工作!和錯誤仍然相同@PrakashSharma – user3153295

回答

0

我已經下面進行我的意見,懇請你找到它,如下它會在你的情況下幫助:

那麼有許多RPC庫(蟒蛇)對於具有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':" [email protected]", 
    'mobile':"7859884833"}) 
print(user_data) 

但我也有找到你所使用的方法execute_kw所以請使用xmlrpclib如果你想使用方法execute_kw

下面是代碼片斷使用它的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

我希望這將幫助你..

+0

非常感謝你@Prakash,但你能解釋我爲什麼我面臨着這樣的錯誤! – user3153295

+0

只需使用odoo.execute。 – prakash

+0

是的,我用它和它的作品給我。但我不明白爲什麼會發生 – user3153295

相關問題