From 04b0da5ce53a825126f132bfcefa7bf817eeb43f Mon Sep 17 00:00:00 2001 From: vigarbuaa Date: Thu, 20 Jun 2019 22:24:03 +0800 Subject: [PATCH] add try/catch to json parse func MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit rest_client认为每个返回都可解为json,在处理alpaca的撤单操作时报错 --- vnpy/api/rest/rest_client.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/vnpy/api/rest/rest_client.py b/vnpy/api/rest/rest_client.py index ead3992f..1af29631 100644 --- a/vnpy/api/rest/rest_client.py +++ b/vnpy/api/rest/rest_client.py @@ -268,9 +268,12 @@ class RestClient(object): request.response = response status_code = response.status_code if status_code // 100 == 2: # 2xx都算成功,尽管交易所都用200 - jsonBody = response.json() - request.callback(jsonBody, request) - request.status = RequestStatus.success + try: + jsonBody = response.json() + request.callback(jsonBody, request) + request.status = RequestStatus.success + except: + print("not json body from request, check body: ",response.text) else: request.status = RequestStatus.failed