Skip to content

Commit

Permalink
Handle connection errors when streaming
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Harmon758 committed Jan 19, 2021
1 parent 3d24a42 commit 68e19cc
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion tweepy/streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from time import sleep

import requests
import urllib3

from tweepy.api import API
from tweepy.error import TweepError
Expand Down Expand Up @@ -247,7 +248,9 @@ def _run(self):
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
Expand Down

0 comments on commit 68e19cc

Please sign in to comment.