Guest User

Untitled

a guest
Feb 12th, 2020
2,004
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.00 KB | None | 0 0
  1. import json
  2. import random
  3. import urllib.request
  4.  
  5. HOST = 'localhost'
  6. PORT = 8069
  7. DB = 'odoo'
  8. USER = 'admin'
  9. PASS = 'admin'
  10.  
  11. def json_rpc(url, method, params):
  12.     data = {
  13.         "jsonrpc": "2.0",
  14.         "method": method,
  15.         "params": params,
  16.         "id": random.randint(0, 1000000000),
  17.     }
  18.     req = urllib.request.Request(url=url, data=json.dumps(data).encode(), headers={
  19.         "Content-Type":"application/json",
  20.     })
  21.     reply = json.loads(urllib.request.urlopen(req).read().decode('UTF-8'))
  22.     if reply.get("error"):
  23.         raise Exception(reply["error"])
  24.     return reply["result"]
  25.  
  26. def call(url, service, method, *args):
  27.     return json_rpc(url, "call", {"service": service, "method": method, "args": args})
  28.  
  29. # log in the given database
  30. url = "http://%s:%s/jsonrpc" % (HOST, PORT)
  31. uid = call(url, "common", "login", DB, USER, PASS)
  32.  
  33. res = call(url, "object", "execute", DB, uid, PASS, 'res.partner', 'search_read', [["id", "=", "1"]],["id", "name", "email"])
  34. print(res)
Advertisement
Add Comment
Please, Sign In to add comment