Improve APIMethod.execute check for 420 and 429 HTTP status codes
authorHarmon <Harmon758@gmail.com>
Wed, 6 Jan 2021 01:19:33 +0000 (19:19 -0600)
committerHarmon <Harmon758@gmail.com>
Wed, 6 Jan 2021 01:19:53 +0000 (19:19 -0600)
Also improve formatting and consistency in comment capitalization

tweepy/binder.py

index a553a2c04ebeb67397fa81667d732ab905f79b82..6193a754a5785ca85f1ddd07f15a0cc8a8831c03 100644 (file)
@@ -198,15 +198,15 @@ def bind_api(**config):
                 reset_time = resp.headers.get('x-rate-limit-reset')
                 if reset_time is not None:
                     self._reset_time = int(reset_time)
-                if self.wait_on_rate_limit and self._remaining_calls == 0 and (
-                        # if ran out of calls before waiting switching retry last call
-                        resp.status_code == 429 or resp.status_code == 420):
+                if (self.wait_on_rate_limit and self._remaining_calls == 0
+                    and resp.status_code in (420, 429)):
+                    # If ran out of calls before waiting switching retry last call
                     continue
                 retry_delay = self.retry_delay
                 # Exit request loop if non-retry error code
                 if resp.status_code in (200, 204):
                     break
-                elif (resp.status_code == 429 or resp.status_code == 420) and self.wait_on_rate_limit:
+                elif resp.status_code in (420, 429) and self.wait_on_rate_limit:
                     if 'retry-after' in resp.headers:
                         retry_delay = float(resp.headers['retry-after'])
                 elif self.retry_errors and resp.status_code not in self.retry_errors: