Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
3 Vastaukset
3536 Näkymät

Hi
I'm testing odoo external APi and I'm getting this error when i execute this last command:
models.execute_kw(db, uid, password, 'sale.order', 'search', [[]])
[4, 3, 1]

models.execute_kw(db, uid, password, 'sale.order', 'read', [1])

Traceback (most recent call last):
File "", line 1, in
File "C:\Users\xenic82661\AppData\Local\Programs\Python\Python39\lib\xmlrpc\client.py", line 1116, in __call__
return self.__send(self.__name, args)
File "C:\Users\xenic82661\AppData\Local\Programs\Python\Python39\lib\xmlrpc\client.py", line 1458, in __request
response = self.__transport.request(
File "C:\Users\xenic82661\AppData\Local\Programs\Python\Python39\lib\xmlrpc\client.py", line 1160, in request
return self.single_request(host, handler, request_body, verbose)
File "C:\Users\xenic82661\AppData\Local\Programs\Python\Python39\lib\xmlrpc\client.py", line 1176, in single_request
return self.parse_response(resp)
File "C:\Users\xenic82661\AppData\Local\Programs\Python\Python39\lib\xmlrpc\client.py", line 1348, in parse_response
return u.close()
File "C:\Users\xenic82661\AppData\Local\Programs\Python\Python39\lib\xmlrpc\client.py", line 662, in close
raise Fault(**self._stack[0])
xmlrpc.client.Fault: \n\nDuring handling of the above exception, another exception occurred:\n\nTraceback (most recent call last):\n File "/home/odoo/src/odoo/saas-16.1/odoo/addons/base/controllers/rpc.py", line 148, in xmlrpc_2\n response = self._xmlrpc(service)\n File "/home/odoo/src/custom/trial/saas_trial/controllers/main.py", line 266, in _xmlrpc\n res = super(OdooRPC, self)._xmlrpc(service)\n File "/home/odoo/src/odoo/saas-16.1/odoo/addons/base/controllers/rpc.py", line 129, in _xmlrpc\n return xmlrpc.client.dumps((result,), methodresponse=1, allow_none=False)\n File "/usr/lib/python3.10/xmlrpc/client.py", line 981, in dumps\n data = m.dumps(params)\n File "/usr/lib/python3.10/xmlrpc/client.py", line 514, in dumps\n dump(v, write)\n File "/usr/lib/python3.10/xmlrpc/client.py", line 536, in __dump\n f(self, value, write)\n File "/usr/lib/python3.10/xmlrpc/client.py", line 589, in dump_array\n dump(v, write)\n File "/usr/lib/python3.10/xmlrpc/client.py", line 536, in __dump\n f(self, value, write)\n File "/usr/lib/python3.10/xmlrpc/client.py", line 607, in dump_struct\n dump(v, write)\n File "/usr/lib/python3.10/xmlrpc/client.py", line 536, in __dump\n f(self, value, write)\n File "/usr/lib/python3.10/xmlrpc/client.py", line 607, in dump_struct\n dump(v, write)\n File "/usr/lib/python3.10/xmlrpc/client.py", line 526, in __dump\n raise TypeError("cannot marshal %s objects" % type(value))\nTypeError: cannot marshal objects\n'>

 
BTW for res.partner is working without any problem
models.execute_kw(db, uid, password, 'res.partner', 'search', [[]])
[9, 10, 8, 7, 1, 3]

models.execute_kw(db, uid, password, 'res.partner', 'read', [9])

[{'id': 9, 'message_is_follower': True, 'message_follower_ids': [...], 'message_partner_ids': [...], 'message_ids': [...], 'has_message': True, 'message_needaction': False, 'message_needaction_counter': 0, 'message_has_error': False, ...}]

Avatar
Hylkää

seems the shared one line of code is fine for me, to debug more to cross check again, may be this helps: https://www.odoo.com/documentation/16.0/developer/api/external_api.html

Paras vastaus

We are experiencing the same error. Could you please tell me if you solved it?

Avatar
Hylkää

odoo support suggested specifying the exact orders attributes/fields that you want to download
this solved our issue

import xmlrpc.client

url = '<insert_own_db_url>'
db = '<insert_db_name>'

## username and password for uid performing search read
username=''
password=''

common = xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(url))
common.version()

uid = common.authenticate(db, username, password, {})

models = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(url))
models.execute_kw(db, uid, password,
'sale.order', 'search_read',
[[['id', '<', 10]]], # Replace with your own search domain
{'fields': ['id', 'name']}) # replace with necessary fields that you would like to read

Tekijä Paras vastaus

Thanks for your reply Bennie, I already executed the 'search' and this record exists

Avatar
Hylkää
Paras vastaus

You must be used to "search" method before "read" method.
You can used to "read" method when you know exactly recordset of model. Let's reference document for detail.

ids = models.execute_kw(db, uid, password, 'res.partner', 'search', [[['is_company', '=', True]]], {'limit': 1})
[record] = models.execute_kw(db, uid, password, 'res.partner', 'read', [ids])


Avatar
Hylkää
Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
0
heinäk. 21
1409
1
tammik. 23
2306
0
jouluk. 21
2655
1
kesäk. 20
7002
0
marrask. 19
6053