Skip to content

Commit

Permalink
catch request exceptions during streaming
Browse files Browse the repository at this point in the history
This commit reuses twarc.decorators2.catch_request_exceptions in the
context of streaming responses with iter_lines. Hopefully this will
address #505 but it will require testing by people who continue seeing
the error in the wild.
  • Loading branch information
edsu committed Jul 9, 2021
1 parent de19dba commit 1ad9a96
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions twarc/client2.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,7 +438,7 @@ def sample(self, event=None, record_keepalive=False):
generator[dict]: a generator, dict for each tweet.
"""
url = "https://api.twitter.com/2/tweets/sample/stream"
while True:
while catch_request_exceptions(lambda: True):
log.info("Connecting to V2 sample stream")
resp = self.get(url, params=expansions.EVERYTHING.copy(), stream=True)
for line in resp.iter_lines(chunk_size=512):
Expand Down Expand Up @@ -533,7 +533,7 @@ def stream(self, event=None, record_keep_alives=False):
url = "https://api.twitter.com/2/tweets/search/stream"
params = expansions.EVERYTHING.copy()

while True:
while catch_request_exceptions(lambda: True):
log.info("Connecting to V2 stream")
resp = self.get(url, params=params, stream=True)
for line in resp.iter_lines():
Expand All @@ -557,6 +557,7 @@ def stream(self, event=None, record_keep_alives=False):
if self._check_for_disconnect(data):
break


def _timeline(
self,
user_id,
Expand Down
2 changes: 1 addition & 1 deletion twarc/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version = "2.3.7"
version = "2.3.8"

0 comments on commit 1ad9a96

Please sign in to comment.