Handle connection errors when streaming
authorHarmon <Harmon758@gmail.com>
Tue, 19 Jan 2021 09:40:05 +0000 (03:40 -0600)
committerHarmon <Harmon758@gmail.com>
Tue, 19 Jan 2021 09:40:05 +0000 (03:40 -0600)
Handle requests.ConnectionError, urllib3.exceptions.ReadTimeoutError, urllib3.exceptions.ProtocolError

Handling urllib3.exceptions.ProtocolError should handle the reraised/wrapped http.client.IncompleteRead connection error that can occur and resolves #237 and resolves #448

Handling urllib3.exceptions.ReadTimeoutError resolves #750

Handling urllib3.exceptions.ProtocolError should also handle the reraised/wrapped ConnectionResetError that can occur and resolves #1416

tweepy/streaming.py

index 5ebcf4d039816a6d99e91600cfe8b9398a019397..66ac999a72c0559899633846547444c9bf75b8f6 100644 (file)
@@ -12,6 +12,7 @@ from threading import Thread
 from time import sleep
 
 import requests
+import urllib3
 
 from tweepy.api import API
 from tweepy.error import TweepError
@@ -247,7 +248,9 @@ class Stream:
                         self.snooze_time = self.snooze_time_step
                         self.listener.on_connect()
                         self._read_loop(resp)
-                except (requests.Timeout, ssl.SSLError) as exc:
+                except (requests.ConnectionError, requests.Timeout,
+                        ssl.SSLError, urllib3.exceptions.ReadTimeoutError,
+                        urllib3.exceptions.ProtocolError) as exc:
                     # This is still necessary, as a SSLError can actually be
                     # thrown when using Requests
                     # If it's not time out treat it like any other exception