From f1da08893b1ca2e1bf7e7ff89b11eda78c4b8789 Mon Sep 17 00:00:00 2001 From: AnthonyOfSeattle Date: Wed, 16 May 2018 14:00:11 -0700 Subject: [PATCH] Fixes #197: Ensure sleep is always called with a default waittime. Sets waittime to default before checking response.json(). Immediately raises unanticipated exceptions without sleeping. --- matrix_client/api.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/matrix_client/api.py b/matrix_client/api.py index 4ff54f69..05ba58af 100644 --- a/matrix_client/api.py +++ b/matrix_client/api.py @@ -667,6 +667,7 @@ def _send(self, method, path, content=None, query_params={}, headers={}, raise MatrixHttpLibError(e, method, endpoint) if response.status_code == 429: + waittime = self.default_429_wait_ms / 1000 try: waittime = response.json()['retry_after_ms'] / 1000 except KeyError: @@ -674,9 +675,8 @@ def _send(self, method, path, content=None, query_params={}, headers={}, errordata = json.loads(response.json()['error']) waittime = errordata['retry_after_ms'] / 1000 except KeyError: - waittime = self.default_429_wait_ms / 1000 - finally: - sleep(waittime) + pass + sleep(waittime) else: break