Logging in to/connecting Odoo with JSON-RPC
Odoo provides one more type of RPC API: JSON-RPC. As its name suggests, JSON-RPC works in the JSON format and uses the jsonrpc
2.0 specification. In this recipe, we will see how you can log in with JSON-RPC. The Odoo web client itself uses JSON-RPC to fetch data from the server.
Getting ready
In this recipe, we will perform user authentication through JSON-RPC to check whether the given credentials are valid. Make sure you have installed the my_hostel
module and that the server is running on http://localhost:8017
.
How to do it...
Perform the following steps to perform user authentication through RPC:
- Add the
jsonrpc_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:
import json import random import requests server_url = 'http://localhost:8017' db_name = 'cookbook_17e' username = 'admin' password...