From e7e600a7ca969779caf149e22ebf33334daa55eb Mon Sep 17 00:00:00 2001 From: rintaro Date: Sun, 25 Mar 2018 20:29:48 +0900 Subject: [PATCH] fix case of empty response --- pybitflyer/async.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pybitflyer/async.py b/pybitflyer/async.py index 8c8fc5e..c6cfd4e 100644 --- a/pybitflyer/async.py +++ b/pybitflyer/async.py @@ -50,12 +50,16 @@ async def request(self, endpoint, method="GET", params=None): try: if method == 'GET': async with s.get(url, params=params, timeout=self.timeout, headers=header) as r: - contents_json = await r.json() - return contents_json + contents = await r.text() + if len(contents) > 0: + contents = json.loads(contents) + return contents else: # method == "POST": async with s.post(url, data=json.dumps(params), timeout=self.timeout, headers=header) as r: - contents_json = await r.json() - return contents_json + contents = await r.text() + if len(contents) > 0: + contents = json.loads(contents) + return contents except Exception as e: print(e) raise e