Logging in to/connecting Odoo with XML-RPC
In this recipe, we will carry out user authentication through RPC to check whether the credentials (server_url, db_name, username, and password) supplied are valid.
Getting ready
To connect an Odoo instance through RPC, you will need a running Odoo instance to connect with. We will assume that you have the Odoo server running on http://localhost:8017
and that you have installed the my_hostel
module.
How to do it...
Perform the following steps to carry out user authentication through RPC:
- Add the
odoo_authenticate.py
file. You can place this file anywhere you want because the RPC program will work independently. - Add the following code to the file:
from xmlrpc import client server_url = 'http://localhost:8017' db_name = 'cookbook_17e' username = 'admin' password = 'admin' common = client.ServerProxy('%s/xmlrpc/2/common' % server_url) user_id = common.authenticate(db_name...