From d7f2622aa251b2cdc25cf617416cf685d15ce206 Mon Sep 17 00:00:00 2001 From: Harmon Date: Fri, 21 Oct 2022 18:59:51 -0500 Subject: [PATCH] Handle 429 HTTP errors for streaming Resolves #1982 Resolves #1986 --- tweepy/asynchronous/streaming.py | 8 ++++---- tweepy/streaming.py | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/tweepy/asynchronous/streaming.py b/tweepy/asynchronous/streaming.py index bb7c4903c..afe281289 100644 --- a/tweepy/asynchronous/streaming.py +++ b/tweepy/asynchronous/streaming.py @@ -50,7 +50,7 @@ async def _connect( network_error_wait_max = 16 http_error_wait = http_error_wait_start = 5 http_error_wait_max = 320 - http_420_error_wait_start = 60 + http_429_error_wait_start = 60 if self.session is None or self.session.closed: self.session = aiohttp.ClientSession( @@ -98,9 +98,9 @@ async def _connect( error_count += 1 - if resp.status == 420: - if http_error_wait < http_420_error_wait_start: - http_error_wait = http_420_error_wait_start + if resp.status in (420, 429): + if http_error_wait < http_429_error_wait_start: + http_error_wait = http_429_error_wait_start await asyncio.sleep(http_error_wait) diff --git a/tweepy/streaming.py b/tweepy/streaming.py index 3ba87f3c7..e815743c5 100644 --- a/tweepy/streaming.py +++ b/tweepy/streaming.py @@ -63,7 +63,7 @@ def _connect(self, method, url, auth=None, params=None, headers=None, network_error_wait_max = 16 http_error_wait = http_error_wait_start = 5 http_error_wait_max = 320 - http_420_error_wait_start = 60 + http_429_error_wait_start = 60 self.session.headers["User-Agent"] = self.user_agent @@ -110,9 +110,9 @@ def _connect(self, method, url, auth=None, params=None, headers=None, error_count += 1 - if resp.status_code == 420: - if http_error_wait < http_420_error_wait_start: - http_error_wait = http_420_error_wait_start + if resp.status_code in (420, 429): + if http_error_wait < http_429_error_wait_start: + http_error_wait = http_429_error_wait_start sleep(http_error_wait)