我正在尝试使用 odoo 14 的 xmlrpc api。我制作了一个小脚本来做一些测试。在测试中,我进行了读取操作,但出现了异常,尽管我的查询是读取的,但xmlrpc.client.Fault
我尝试修改的 odoo compains 'res.users'
'res.partner'
这是我的测试脚本。(请注意,如果我尝试执行 search_read 而不是 search 然后读取,则错误是相同的)
#! /usr/bin/env python3
import xmlrpc.client
url = <redacted>
base = <redacted>
user = <redacted>
key = <redacted>
try:
api = xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(url))
mod = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(url))
print("connection ... ", end='')
uid = api.authenticate(base, user, key, {})
print("ok. uid=",uid)
print("listing partners ... ", end='')
partners = mod.execute_kw(base, uid, key, 'res.partner', 'search', [[]])
print("ok. partners=", partners)
print("fetching partner ... ", end='')
res = mod.execute_kw(base, uid, key, 'res.partner', 'read', partners[:1])
print("ok. partner=", res)
except xmlrpc.client.Fault as e:
print("error !!!")
print(str(e))
如果我运行此代码,我会得到:
connection ... ok. uid= 6
listing partners ... ok. partners= [3, 15, 7, 10, 8, 9, 14, 13, 12, 11, 1, 16]
fetching partner ... error !!!
<Fault 4: "You are not allowed to modify 'Users' (res.users) records.\n\nThis operation is allowed for the following groups:\n\t- Administration/Access Rights\n\nContact your administrator to request access if necessary.">
我不明白为什么它试图修改任何东西,因为我正在阅读.
是因为相关模型中的计算字段吗?考虑到这一点,我还尝试选择我想要的字段,并且在此示例中代码有效:
print("fetching partner names ... ", end='')
res = mod.execute_kw(base, uid, key, 'res.partner', 'read', partners[:1], {'fields': ['name']})
print("ok. names=", res)
编辑:
请注意,当使用具有读取权限但没有写入权限的用户登录时,会出现此问题。