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 = 'test-12'
username = 'admin'
password = 'admin'
common = client.ServerProxy('%s/xmlrpc/2/common' % server_url)
user_id = common.authenticate(db_name, username, password, {})
if user_id:
print("Success: User id is", user_id)
else:
print("Failed: wrong credentials")
- Run the following Python script from the Terminal with the following command:
python3 odoo_authenticate.py
This will print a success message with the user ID if you have provided a valid login name and password.