From: Harmon Date: Tue, 19 Jan 2021 09:40:05 +0000 (-0600) Subject: Handle connection errors when streaming X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=68e19cc6b9b23d72369ca1520093770eb18a5a9f;p=tweepy.git Handle connection errors when streaming 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 --- diff --git a/tweepy/streaming.py b/tweepy/streaming.py index 5ebcf4d..66ac999 100644 --- a/tweepy/streaming.py +++ b/tweepy/streaming.py @@ -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