Skip to content

Commit

Permalink
Merge pull request #95 from NielsOerbaek/main
Browse files Browse the repository at this point in the history
Handle unknown authorization error with status 200
  • Loading branch information
vladkens authored Dec 26, 2023
2 parents 03d0abb + 87acabb commit ae4419c
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions twscrape/queue_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,14 @@ class RateLimitError(Exception):
class BannedError(Exception):
pass


class DependencyError(Exception):
pass


class UnknownAuthorizationError(Exception):
pass


def req_id(rep: httpx.Response):
lr = str(rep.headers.get("x-rate-limit-remaining", -1))
ll = str(rep.headers.get("x-rate-limit-limit", -1))
Expand Down Expand Up @@ -170,10 +173,16 @@ async def _check_rep(self, rep: httpx.Response):
if rep.status_code == 200 and "_Missing: No status found with that ID." in msg:
return # ignore this error

if rep.status_code == 200 and "Authorization" in msg:
return # ignore this error
raise UnknownAuthorizationError(msg)

# todo: (32) Could not authenticate you

if msg != "OK":
raise ApiError(rep, res)
logger.error(f"Unknown error: {msg}")
return # ignore this error
#raise ApiError(rep, res)

rep.raise_for_status()

Expand All @@ -197,7 +206,10 @@ async def req(self, method: str, url: str, params: ReqParams = None):
# already handled
continue
except DependencyError:
logger.error(f"Dependency error, returnning: {url}")
logger.error(f"Dependency error, returning: {url}")
return
except UnknownAuthorizationError:
logger.error(f"Unknown authorization error, returning: {url}")
return
except (httpx.ReadTimeout, httpx.ProxyError):
# http transport failed, just retry
Expand Down

0 comments on commit ae4419c

Please sign in to comment.