Skip to content

Commit

Permalink
Output a warning when an HTTP page fails to load
Browse files Browse the repository at this point in the history
This creates a message that the user can see. We will flesh out this
message to include better explainations for each situation in later
commits.
  • Loading branch information
uranusjr committed Aug 9, 2020
1 parent 102fb0a commit 0189f48
Showing 1 changed file with 8 additions and 19 deletions.
27 changes: 8 additions & 19 deletions src/pip/_internal/index/collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from optparse import Values
from typing import (
Callable, Iterable, List, MutableMapping, Optional,
Protocol, Sequence, Tuple, TypeVar, Union,
Protocol, Sequence, Tuple, TypeVar,
)
import xml.etree.ElementTree

Expand Down Expand Up @@ -404,17 +404,6 @@ def __str__(self):
return redact_auth_from_url(self.url)


def _handle_get_page_fail(
link, # type: Link
reason, # type: Union[str, Exception]
meth=None # type: Optional[Callable[..., None]]
):
# type: (...) -> None
if meth is None:
meth = logger.debug
meth("Could not fetch URL %s: %s - skipping", link, reason)


def _make_html_page(response, cache_link_parsing=True):
# type: (Response, bool) -> HTMLPage
encoding = _get_encoding_from_headers(response.headers)
Expand Down Expand Up @@ -465,17 +454,17 @@ def _get_html_page(link, session=None):
link, exc.request_desc, exc.content_type,
)
except NetworkResponseError as exc:
_handle_get_page_fail(link, exc)
logger.warning("Could not fetch URL %s: %s", link, exc)
except RetryError as exc:
_handle_get_page_fail(link, exc)
logger.warning("Could not fetch URL %s: %s", link, exc)
except SSLError as exc:
reason = "There was a problem confirming the ssl certificate: "
reason += str(exc)
_handle_get_page_fail(link, reason, meth=logger.info)
reason = "There was a problem confirming the ssl certificate"
logger.warning("Could not fetch URL %s: %s: %s", link, reason, exc)
except requests.ConnectionError as exc:
_handle_get_page_fail(link, "connection error: {}".format(exc))
reason = "connection error"
logger.warning("Could not fetch URL %s: %s: %s", link, reason, exc)
except requests.Timeout:
_handle_get_page_fail(link, "timed out")
logger.warning("Could not fetch URL %s: %s", link, "timed out")
else:
return _make_html_page(
resp, cache_link_parsing=link.cache_link_parsing,
Expand Down

0 comments on commit 0189f48

Please sign in to comment.