Skip to content

Commit

Permalink
Handle 429 HTTP errors for streaming
Browse files Browse the repository at this point in the history
Resolves #1982
Resolves #1986
  • Loading branch information
Harmon758 committed Oct 21, 2022
1 parent 42c80d4 commit d7f2622
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions tweepy/asynchronous/streaming.py
Expand Up @@ -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(
Expand Down Expand Up @@ -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)

Expand Down
8 changes: 4 additions & 4 deletions tweepy/streaming.py
Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit d7f2622

Please sign in to comment.