Skip to content
Snippets Groups Projects
Unverified Commit b856561f authored by Andreas Perhab's avatar Andreas Perhab Committed by Martin Trigaux
Browse files

[FIX] doc: json rpc example

Could crash if note was note installed.
Add example of parameters to connect to the database

Closes #24085
parent 75f8eef2
No related branches found
No related tags found
No related merge requests found
......@@ -1709,12 +1709,19 @@ JSON-RPC Library
----------------
The following example is a Python 3 program that interacts with an Odoo server
with the standard Python libraries ``urllib.request`` and ``json``::
with the standard Python libraries ``urllib.request`` and ``json``. This
example assumes the **Productivity** app (``note``) is installed::
import json
import random
import urllib.request
HOST = 'localhost'
PORT = 8069
DB = 'openacademy'
USER = 'admin'
PASS = 'admin'
def json_rpc(url, method, params):
data = {
"jsonrpc": "2.0",
......@@ -1725,7 +1732,7 @@ with the standard Python libraries ``urllib.request`` and ``json``::
req = urllib.request.Request(url=url, data=json.dumps(data).encode(), headers={
"Content-Type":"application/json",
})
reply = json.load(urllib.request.urlopen(req))
reply = json.loads(urllib.request.urlopen(req).read().decode('UTF-8'))
if reply.get("error"):
raise Exception(reply["error"])
return reply["result"]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment