This question has been flagged
1 Reply
4633 Views

error while testing Python xml-rpc client, data for res.partner showing successfully, but for products it is showing error, below are my python file and output on terminal. please help to resolve what mistake i made here.

Python file:

url = 'http://192.168.18.71:8069'
db = 'odb'
username = 'odoouser@myhost.com'
password = 'admin'
import xmlrpc.client

common = xmlrpc.client.ServerProxy('{}/xmlrpc/2/common'.format(url))
uid = common.authenticate(db, username, password, {})
version = common.version()
print("details...", version)
print("User ID = ", uid)
models = xmlrpc.client.ServerProxy('{}/xmlrpc/2/object'.format(url))
#
# test to get res.partner data
#
partners = models.execute_kw(db, uid, password, 'res.partner', 'search', [[['is_company', '=', False]]], {'offset': 10, 'limit': 10})
partners_rec = models.execute_kw(db, uid, password, 'res.partner', 'read', [partners], {'fields': ['id', 'name']})
print("partners data start here....")
for partner in partners_rec:
    print(partner)
print("partner data end here....")
print(" ")
#
# test to get product.template data
#
products = models.execute_kw(db, uid, password, 'product.template', {'offset': 10, 'limit': 10})
products_rec = models.execute_kw(db, uid, password, 'product.template', 'read', [products], {'fields': ['id', 'name']})
print("products data start here....")
for prod in products_rec:
    print(prod)
print("products data end here....")
print(" ")

Output:

details... {'server_version': '14.0', 'server_version_info': [14, 0, 0, 'final', 0, ''], 'server_serie': '14.0', 'protocol_version': 1}
User ID =  2
partners data start here....
{'id': 20, 'name': 'Edwin Hansen'}
{'id': 22, 'name': 'Jesse Brown'}
{'id': 31, 'name': 'Oscar Morgan'}
{'id': 23, 'name': 'Soham Palmer'}
{'id': 54, 'name': 'JohnSmith'}
{'id': 34, 'name': 'Lorraine Douglas'}
{'id': 50, 'name': 'Maqsood Sb.'}
{'id': 42, 'name': 'Mark Demo'}
{'id': 41, 'name': 'Mitchell Admin'}
{'id': 44, 'name': 'Jeff Lawson'}
partner data end here....
 
Traceback (most recent call last):
  File "/usr/lib/python3.6/runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.6/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/home/odoo/odoo-dev/odoo/odoo_xmlrpc.py", line 28, in <module>
    products = models.execute_kw(db, uid, password, 'product.template', {'offset': 10, 'limit': 10})
  File "/usr/lib/python3.6/xmlrpc/client.py", line 1112, in __call__
    return self.__send(self.__name, args)
  File "/usr/lib/python3.6/xmlrpc/client.py", line 1452, in __request
    verbose=self.__verbose
  File "/usr/lib/python3.6/xmlrpc/client.py", line 1154, in request
    return self.single_request(host, handler, request_body, verbose)
  File "/usr/lib/python3.6/xmlrpc/client.py", line 1170, in single_request
    return self.parse_response(resp)
  File "/usr/lib/python3.6/xmlrpc/client.py", line 1342, in parse_response
    return u.close()
  File "/usr/lib/python3.6/xmlrpc/client.py", line 656, in close
    raise Fault(**self._stack[0])
xmlrpc.client.Fault: <Fault 1: 'Traceback (most recent call last):\n  File "/home/odoo/odoo-dev/odoo/odoo/addons/base/controllers/rpc.py", line 69, in xmlrpc_2\n    response = self._xmlrpc(service)\n  File "/home/odoo/odoo-dev/odoo/odoo/addons/base/controllers/rpc.py", line 49, in _xmlrpc\n    result = dispatch_rpc(service, method, params)\n  File "/home/odoo/odoo-dev/odoo/odoo/http.py", line 140, in dispatch_rpc\n    result = dispatch(method, params)\n  File "/home/odoo/odoo-dev/odoo/odoo/service/model.py", line 41, in dispatch\n    res = fn(db, uid, *params)\nTypeError: execute_kw() missing 1 required positional argument: \'args\'\n'>


Avatar
Discard
Author Best Answer

problem resolved... modified line below --  added 'search', [[]]  --: 

products = models.execute_kw(db, uid, password, 'product.template', 'search', [[]])
Avatar
Discard