diff --git a/huobi/connection/impl/restapi_invoker.py b/huobi/connection/impl/restapi_invoker.py index 4466abf..838e6df 100644 --- a/huobi/connection/impl/restapi_invoker.py +++ b/huobi/connection/impl/restapi_invoker.py @@ -8,6 +8,16 @@ session = requests.Session() + +def json_loads(text, encoding='utf-8'): + from sys import version_info + if version_info.major > 3: + return json.loads(text) + if version_info.minor > 7: + return json.loads(text) + return json.loads(text, encoding=encoding) + + def check_response(dict_data): status = dict_data.get("status", None) code = dict_data.get("code", None) @@ -53,30 +63,31 @@ def call_sync(request, is_checked=False): response = session.get(request.host + request.url, headers=request.header) if is_checked is True: return response.text - dict_data = json.loads(response.text, encoding="utf-8") + dict_data = json_loads(response.text) # print("call_sync === recv data : ", dict_data) check_response(dict_data) return request.json_parser(dict_data) elif request.method == "POST": response = session.post(request.host + request.url, data=json.dumps(request.post_body), headers=request.header) - dict_data = json.loads(response.text, encoding="utf-8") + dict_data = json_loads(response.text) # print("call_sync === recv data : ", dict_data) check_response(dict_data) return request.json_parser(dict_data) + def call_sync_perforence_test(request, is_checked=False): if request.method == "GET": inner_start_time = time.time() # print("call_sync_perforence_test url : ", request.host + request.url) response = session.get(request.host + request.url, headers=request.header) - #print("call_sync_perforence_test data :", response.text) + # print("call_sync_perforence_test data :", response.text) inner_end_time = time.time() cost_manual = round(inner_end_time - inner_start_time, 6) req_cost = response.elapsed.total_seconds() if is_checked is True: return response.text - dict_data = json.loads(response.text, encoding="utf-8") + dict_data = json_loads(response.text) # print("call_sync === recv data : ", dict_data) check_response(dict_data) return request.json_parser(dict_data), req_cost, cost_manual @@ -87,7 +98,7 @@ def call_sync_perforence_test(request, is_checked=False): inner_end_time = time.time() cost_manual = round(inner_end_time - inner_start_time, 6) req_cost = response.elapsed.total_seconds() - dict_data = json.loads(response.text, encoding="utf-8") + dict_data = json_loads(response.text) # print("call_sync === recv data : ", dict_data) check_response(dict_data) return request.json_parser(dict_data), req_cost, cost_manual