-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJSONRPC_webservices.py
40 lines (34 loc) · 1012 Bytes
/
JSONRPC_webservices.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import json
import random
import urllib.request
# import urllib.request as urllib
import urllib3
HOST = 'localhost'
PORT = 8011
DB = 'uber'
USER = 'admin'
PASS = 'a'
def json_rpc(url,method,params):
data = {
"jsonrpc" : "2.0",
"method" : method,
"params" : params,
"id" : random.randint(0,1000),
}
req = urllib.Request(url=url,data=json.dumps(data),
headers={"Content-Type":"application/json",
})
reply = json.load(urllib.urlopen(req))
if reply.get("error"):
raise Exception(reply["error"])
return reply["result"]
def call(url,service,method,*args):
return json_rpc(url,"call",{"service":service,"method":method,"args":args})
#Log in the given database
url = "http://%s:%s/jsonrpc" % (HOST,PORT)
userid = call(url,"common","login",DB,USER,PASS)
#Edir record
args = {
'name' : 'NONAME',
}
data_id = call(url,"object","execute",DB,userid,PASS,'guest.user','write',[2],args)