Running server methods using XML-RPC
With XML-RPC, no session is maintained and the authentication credentials are sent with every request. This adds some overhead to the protocol, but makes it simpler to use.
Â
Â
Next, we set up access to the server methods that need a login to be accessed. These are exposed at the /xmlrpc/2/object
endpoint, as shown in the following:
>>> api = client.ServerProxy('%s/xmlrpc/2/object' % srv)
>>> api.execute_kw(db, uid, pwd, 'res.partner', 'search_count', [[]])
42
Here, we are accessing the server API for the first time, performing a count on the Partner records. Methods are called using the execute_kw()
method that takes the following arguments:
- The name of the database to connect to
- The connection user ID
- The user password
- The target model identifier name
- The method to call
- A list of positional arguments
- An optional dictionary with keyword arguments (not used in the example)
The preceding example calls the search_count
method of the res.partner
model...