[FIX] doc: json rpc example
Could crash if note was note installed. Add example of parameters to connect to the database Closes #24085
This commit is contained in:
@@ -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"]
|
||||
|
||||
Reference in New Issue
Block a user