Ensure HTTPError.response is not None
The implementation of `HTTPError` in `requests` does not guarantee that the `response` property will always be set. So we need to ensure it is not `None` before looking for the return code, for example. This also makes mypy checks pass again, as `types-request` was updated in 2.31.0.9 to better match this particular aspect. See: https://github.com/python/typeshed/pull/10875
This commit is contained in:
parent
968ddef295
commit
7344d264e7
7 changed files with 8 additions and 2 deletions
|
@ -127,6 +127,7 @@ class BioconductorLister(Lister[BioconductorListerState, BioconductorListerPage]
|
|||
packages_txt = self.http_request(url).text
|
||||
packages = self.parse_packages(packages_txt)
|
||||
except HTTPError as e:
|
||||
assert e.response is not None
|
||||
logger.debug(
|
||||
"Skipping page since got %s response for %s",
|
||||
e.response.status_code,
|
||||
|
|
|
@ -125,7 +125,7 @@ class BitbucketLister(Lister[BitbucketListerState, List[Dict[str, Any]]]):
|
|||
body = self.http_request(self.url, params=self.url_params).json()
|
||||
yield body["values"]
|
||||
except HTTPError as e:
|
||||
if e.response.status_code == 500:
|
||||
if e.response is not None and e.response.status_code == 500:
|
||||
logger.warning(
|
||||
"URL %s is buggy (error 500), skip it and get next page.",
|
||||
e.response.url,
|
||||
|
|
|
@ -160,6 +160,7 @@ class CGitLister(StatelessLister[Repositories]):
|
|||
try:
|
||||
bs = self._get_and_parse(repository_url)
|
||||
except HTTPError as e:
|
||||
assert e.response is not None
|
||||
logger.warning(
|
||||
"Unexpected HTTP status code %s on %s",
|
||||
e.response.status_code,
|
||||
|
|
|
@ -56,6 +56,7 @@ def _if_rate_limited(retry_state) -> bool:
|
|||
exc = attempt.exception()
|
||||
return (
|
||||
isinstance(exc, HTTPError)
|
||||
and exc.response is not None
|
||||
and exc.response.status_code == codes.forbidden
|
||||
and int(exc.response.headers.get("RateLimit-Remaining", "0")) == 0
|
||||
) or is_retryable_exception(exc)
|
||||
|
|
|
@ -125,6 +125,7 @@ class GitwebLister(StatelessLister[Repositories]):
|
|||
try:
|
||||
bs = self._get_and_parse(repository_url)
|
||||
except HTTPError as e:
|
||||
assert e.response is not None
|
||||
logger.warning(
|
||||
"Unexpected HTTP status code %s on %s",
|
||||
e.response.status_code,
|
||||
|
|
|
@ -135,7 +135,8 @@ class GogsLister(Lister[GogsListerState, GogsListerPage]):
|
|||
response = self.http_request(url, params=params)
|
||||
except HTTPError as http_error:
|
||||
if (
|
||||
http_error.response.status_code == 500
|
||||
http_error.response is not None
|
||||
and http_error.response.status_code == 500
|
||||
): # Temporary hack for skipping fatal repos (T4423)
|
||||
url_parts = urlparse(url)
|
||||
query: Dict[str, Any] = dict(parse_qsl(url_parts.query))
|
||||
|
|
|
@ -113,6 +113,7 @@ class StagitLister(StatelessLister[Repositories]):
|
|||
try:
|
||||
bs = self._get_and_parse(repository_url)
|
||||
except HTTPError as e:
|
||||
assert e.response is not None
|
||||
logger.warning(
|
||||
"Unexpected HTTP status code %s on %s",
|
||||
e.response.status_code,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue