Handle 429 HTTP errors for streaming
authorHarmon <Harmon758@gmail.com>
Fri, 21 Oct 2022 23:59:51 +0000 (18:59 -0500)
committerHarmon <Harmon758@gmail.com>
Fri, 21 Oct 2022 23:59:51 +0000 (18:59 -0500)
Resolves #1982
Resolves #1986

tweepy/asynchronous/streaming.py
tweepy/streaming.py

index bb7c4903c3db6c3222b21ca930b02042d398a59f..afe281289059a82e2f8507ec023a952dc1e9bb1d 100644 (file)
@@ -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)
 
index 3ba87f3c7e02b28eae7c103ea129d798eb2ce206..e815743c5968c03d676557601281310b33c873a0 100644 (file)
@@ -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)