From b856561f8908f144e855d265cc140835e5cf22b2 Mon Sep 17 00:00:00 2001 From: Andreas Perhab Date: Fri, 6 Apr 2018 11:43:42 +0200 Subject: [PATCH] [FIX] doc: json rpc example Could crash if note was note installed. Add example of parameters to connect to the database Closes #24085 --- doc/howtos/backend.rst | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/doc/howtos/backend.rst b/doc/howtos/backend.rst index ddc41dca404..933309ad190 100644 --- a/doc/howtos/backend.rst +++ b/doc/howtos/backend.rst @@ -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"]