Odoo xmlrpc TypeError:不可用类型'list'

时间:2017-09-06 12:44:31

标签: python openerp odoo-10 xmlrpclib

我正在尝试使用xmlrpclib.ServerProxy在odoo10服务器上执行方法。它会加载名为 DummyCountry 的所有国家/地区,但只会加载 name id 字段。但它抛出一个TypeError: unhashable type 'list'。奇怪的是,这段代码一直有效。有人可以解释一下发生了什么吗?

带问题的代码行:

# sock is of type xmlrpclib.ServerProxy
countries = sock.execute_kw(
    db, # database
    uid, # user id
    pwd, # password
    'res.country', # model
    'search_read', # method
    [[['name', '=', 'DummyCountry']]], # expressions
    {'fields': ['name']} # additional parameters? (id is included automatically)
)

错误:

Traceback (most recent call last):
  File "/opt/odoo/odoo10/odoo/service/wsgi_server.py", line 56, in xmlrpc_return
  result = odoo.http.dispatch_rpc(service, method, params)
  File "/opt/odoo/odoo10/odoo/http.py", line 118, in dispatch_rpc
    result = dispatch(method, params)
  File "/opt/odoo/odoo10/odoo/service/model.py", line 38, in dispatch
 res = fn(db, uid, *params)
  File "/opt/odoo/odoo10/odoo/service/model.py", line 119, in wrapper
    return f(dbname, *args, **kwargs)
  File "/opt/odoo/odoo10/odoo/service/model.py", line 182, in execute
    res = execute_cr(cr, uid,obj, method, *args, **kw)
  File "/opt/odoo/odoo10/odoo/service/model.py", line 171, in execute_cr
    return odoo.api.call_kw(recs, method, args, kw)
  File "/opt/odoo/odoo10/odoo/api.py", line 679, in call_kw
    return call_kw_model(method, model, args, kwargs)
  File "/opt/odoo/odoo10/odoo/api.py", line 664, in call_kw_model
    result = method(recs, *args, **kwargs)
  File "/opt/odoo/odoo10/odoo/models.py", line 4670, in search_read
    records = self.search(domain or [], offset=offset, limit=limit, order=order)
  File "/opt/odoo/odoo10/odoo/models.py", line 1509, in search
    res = self._search(args, offset=offset,limit=limit, order=order, count=count)
  File "/opt/odoo/odoo10/odoo/models.py", line 4215, in _search
    query = self._where_calc(args)
  File "/opt/odoo/odoo10/odoo/models.py", line 4014, in _where_calc
    e = expression.expression(domain, self)
  File "/opt/odoo/odoo10/odoo/osv/expression.py", line 640, in __init__
    self.expression = distribute_not(normalize_domain(domain))
  File "/opt/odoo/odoo10/odoo/osv/expression.py", line 289, in distribute_not
    eliftoken in DOMAIN_OPERATORS_NEGATION:
TypeError: unhashable type: 'list'

1 个答案:

答案 0 :(得分:0)

尝试以下代码。

import xmlrpclib
url = 'http://192.168.50.35:6060'
db = 'shop'
username = 'admin'
password = 'admin'
common = xmlrpclib.ServerProxy('{}/xmlrpc/2/common'.format(url))
uid = common.authenticate(db, username, password, {})
models = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format(url))
ids = models.execute_kw(db, uid, password,
'res.country', # model
'search_read', # method
[[['name', '=', 'India']]], # expressions
{'fields': ['name']})
print'idsssss',ids

<强>输出

idsssss [{'id': 105, 'name': 'India'}]

希望它会对你有所帮助。