Logging in to/connecting Odoo with XML-RPC
In this recipe, we will carry out user authentication through RPC to check whether the credentials 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:8069
and that you have installed the my_library
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:8069' db_name = 'book-db-14' username = 'admin' password = 'admin' common = client.ServerProxy('%s/xmlrpc/2/common' %Â Â Â Â Â Â Â Â server_url) user_id = common.authenticate(db_name...