From: Harmon Date: Fri, 21 Oct 2022 23:59:51 +0000 (-0500) Subject: Handle 429 HTTP errors for streaming X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=d7f2622aa251b2cdc25cf617416cf685d15ce206;p=tweepy.git Handle 429 HTTP errors for streaming Resolves #1982 Resolves #1986 --- diff --git a/tweepy/asynchronous/streaming.py b/tweepy/asynchronous/streaming.py index bb7c490..afe2812 100644 --- a/tweepy/asynchronous/streaming.py +++ b/tweepy/asynchronous/streaming.py @@ -50,7 +50,7 @@ class AsyncBaseStream: 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 @@ class AsyncBaseStream: 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 3ba87f3..e815743 100644 --- a/tweepy/streaming.py +++ b/tweepy/streaming.py @@ -63,7 +63,7 @@ class BaseStream: 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 @@ class BaseStream: 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)