Skip to content

Commit

Permalink
Merge pull request #5483 from popravich/retry_fix
Browse files Browse the repository at this point in the history
Handle RetryError in HTMLPage (fixes #5270)
  • Loading branch information
xavfernandez authored Oct 8, 2018
2 parents 33a6716 + 290e3d5 commit 3832020
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
2 changes: 2 additions & 0 deletions news/5270.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Handle `requests.exceptions.RetryError` raised in `PackageFinder` that was
causing pip to fail silently when some indexes were unreachable.
2 changes: 2 additions & 0 deletions news/5483.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Handle `requests.exceptions.RetryError` raised in `PackageFinder` that was
causing pip to fail silently when some indexes were unreachable.
4 changes: 3 additions & 1 deletion src/pip/_internal/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from pip._vendor.packaging import specifiers
from pip._vendor.packaging.utils import canonicalize_name
from pip._vendor.packaging.version import parse as parse_version
from pip._vendor.requests.exceptions import SSLError
from pip._vendor.requests.exceptions import RetryError, SSLError
from pip._vendor.six.moves.urllib import parse as urllib_parse
from pip._vendor.six.moves.urllib import request as urllib_request

Expand Down Expand Up @@ -163,6 +163,8 @@ def _get_html_page(link, session=None):
inst = HTMLPage(resp.content, resp.url, resp.headers)
except requests.HTTPError as exc:
_handle_get_page_fail(link, exc, url)
except RetryError as exc:
_handle_get_page_fail(link, exc, url)
except SSLError as exc:
reason = "There was a problem confirming the ssl certificate: "
reason += str(exc)
Expand Down
31 changes: 29 additions & 2 deletions tests/unit/test_index.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import logging
import os.path

import pytest
from pip._vendor import html5lib
from mock import Mock
from pip._vendor import html5lib, requests

from pip._internal.download import PipSession
from pip._internal.index import (
Link, PackageFinder, _determine_base_url, egg_info_matches,
Link, PackageFinder, _determine_base_url, _get_html_page, egg_info_matches,
)


Expand Down Expand Up @@ -190,3 +192,28 @@ def test_egg_info_matches(egg_info, search_name, expected):
link = None # Only used for reporting.
version = egg_info_matches(egg_info, search_name, link)
assert version == expected


def test_request_http_error(caplog):
caplog.set_level(logging.DEBUG)
link = Link('http://localhost')
session = Mock(PipSession)
session.get.return_value = resp = Mock()
resp.raise_for_status.side_effect = requests.HTTPError('Http error')
assert _get_html_page(link, session=session) is None
assert (
'Could not fetch URL http://localhost: Http error - skipping'
in caplog.text
)


def test_request_retries(caplog):
caplog.set_level(logging.DEBUG)
link = Link('http://localhost')
session = Mock(PipSession)
session.get.side_effect = requests.exceptions.RetryError('Retry error')
assert _get_html_page(link, session=session) is None
assert (
'Could not fetch URL http://localhost: Retry error - skipping'
in caplog.text
)

0 comments on commit 3832020

Please sign in to comment.