Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
3 ตอบกลับ
4547 มุมมอง

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, ...}]

อวตาร
ละทิ้ง

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

คำตอบที่ดีที่สุด

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

อวตาร
ละทิ้ง

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

ผู้เขียน คำตอบที่ดีที่สุด

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

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

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])


อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
0
ก.ค. 21
1915
1
ม.ค. 23
2842
0
ธ.ค. 21
3274
1
มิ.ย. 20
7929
0
พ.ย. 19
6566