summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Perhab <andreas.perhab@wt-io-it.at>2018-04-06 11:43:42 +0200
committerMartin Trigaux <mat@odoo.com>2018-04-09 17:31:19 +0200
commitb856561f8908f144e855d265cc140835e5cf22b2 (patch)
tree696ce3f0eca7e5972a84b1d79e39114dc618c827
parent75f8eef26d0d79370ad83cdd20be8abb3d9a4f8c (diff)
[FIX] doc: json rpc example
Could crash if note was note installed. Add example of parameters to connect to the database Closes #24085
-rw-r--r--doc/howtos/backend.rst11
1 files 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"]