From dcfbfade4ec9986e5d50bc39dcbaa7bd1f29ca2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20=C3=98rb=C3=A6k=20Chemnitz?= Date: Mon, 9 Oct 2023 16:14:02 +0200 Subject: [PATCH] Handle dependency error --- twscrape/queue_client.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/twscrape/queue_client.py b/twscrape/queue_client.py index 436300c..454cd50 100644 --- a/twscrape/queue_client.py +++ b/twscrape/queue_client.py @@ -39,6 +39,9 @@ class RateLimitError(Exception): class BannedError(Exception): pass +class DependencyError(Exception): + pass + def req_id(rep: httpx.Response): lr = str(rep.headers.get("x-rate-limit-remaining", -1)) @@ -155,6 +158,9 @@ async def _check_rep(self, rep: httpx.Response): await self._close_ctx(-1, banned=True, msg=msg) raise BannedError(msg) + if msg.startswith("(131) Dependency: Internal error."): + raise DependencyError(msg) + # possible banned by old api flow if rep.status_code in (401, 403): await self._close_ctx(utc_ts() + 60 * 60 * 12) # lock for 12 hours @@ -190,6 +196,9 @@ async def req(self, method: str, url: str, params: ReqParams = None): except (RateLimitError, BannedError): # already handled continue + except (DependencyError): + logger.error(f"Dependency error, returnning: {url}") + return except (httpx.ReadTimeout, httpx.ProxyError): # http transport failed, just retry continue