forked from qcware/platform_client_library_python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequest.py
More file actions
32 lines (26 loc) · 845 Bytes
/
request.py
File metadata and controls
32 lines (26 loc) · 845 Bytes
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
import ast
import json
import pickle
import requests
import param_utils
def pickle_json(json_object):
if isinstance(json_object, dict):
r = {}
for k, v in json_object.items():
if k != 'Q':
r[k] = pickle_json(v)
else:
r['Q'] = pickle.dumps(v, protocol=0)
return r
elif isinstance(json_object, list):
return [pickle_json(elem) for elem in json_object]
else:
return pickle.dumps(json_object, protocol=0)
def post(api_endpoint_url, param_dictionary):
pbuffed_params = param_utils.convert(param_dictionary)
r = requests.post(api_endpoint_url,
data=pbuffed_params.SerializeToString())
r = json.loads(r.text)
if r.get('solution'):
r['solution'] = ast.literal_eval(r['solution'])
return r