From 2ada76df178bad49286fe782809d3d9dc3a447e3 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 | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/pybitflyer/async.py b/pybitflyer/async.py index 8c8fc5e..e2f3be6 100644 --- a/pybitflyer/async.py +++ b/pybitflyer/async.py @@ -50,12 +50,18 @@ 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 + try: + contents = await r.json() + except: + contents = await r.text() + 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 + try: + contents = await r.json() + except: + contents = await r.text() + return contents except Exception as e: print(e) raise e