Skip to content

Commit

Permalink
Catch errors in stream
Browse files Browse the repository at this point in the history
The iter_lines() call in Twarc2.stream needs to catch more than
HTTP errors. See #471 for details.
  • Loading branch information
edsu committed Jul 1, 2021
1 parent 2e6fa20 commit cea8138
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions twarc/client2.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,13 +503,18 @@ def sample(self, event=None, record_keepalive=False):
time.sleep(5)
break

except requests.exceptions.HTTPError as e:
except requests.exceptions.RequestException as e:
errors += 1
log.error("caught http error %s on %s try", e, errors)
log.error("caught request error %s on %s try", e, errors)

if self.http_errors and errors == self.http_errors:
log.warning("too many errors")
raise e
if e.response.status_code == 420:

if (
isinstance(e, requests.exceptions.HTTPError)
and response.status_code == 420
):
if interruptible_sleep(errors * 60, event):
log.info("stopping filter")
return
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.2"
version = "2.3.3"

0 comments on commit cea8138

Please sign in to comment.