mirror of https://github.com/pypa/pip
Ensure that we successfully utilize requests timeout functionality
This commit is contained in:
parent
a8b94878f3
commit
92c40c3e06
|
@ -147,14 +147,11 @@ class PipSession(requests.Session):
|
|||
if parsed.scheme == "file":
|
||||
url = urlparse.urlunparse(parsed[:1] + ("localhost",) + parsed[2:])
|
||||
|
||||
# Dispatch the actual request
|
||||
return super(PipSession, self).request(method, url, *args, **kwargs)
|
||||
|
||||
def send(self, *args, **kwargs):
|
||||
# Allow setting a default timeout on a session
|
||||
kwargs.setdefault("timeout", self.timeout)
|
||||
|
||||
return super(PipSession, self).send(*args, **kwargs)
|
||||
# Dispatch the actual request
|
||||
return super(PipSession, self).request(method, url, *args, **kwargs)
|
||||
|
||||
|
||||
def get_file_content(url, comes_from=None, session=None):
|
||||
|
|
25
pip/index.py
25
pip/index.py
|
@ -22,8 +22,8 @@ from pip.backwardcompat import CertificateError
|
|||
from pip.download import PipSession, path_to_url2, url_to_path
|
||||
from pip.wheel import Wheel, wheel_ext, wheel_setuptools_support, setuptools_requirement
|
||||
from pip.pep425tags import supported_tags, supported_tags_noarch, get_platform
|
||||
from pip.vendor import html5lib
|
||||
from pip.vendor.requests import HTTPError
|
||||
from pip.vendor import html5lib, requests
|
||||
|
||||
|
||||
__all__ = ['PackageFinder']
|
||||
|
||||
|
@ -669,14 +669,14 @@ class HTMLPage(object):
|
|||
return None
|
||||
|
||||
inst = cls(resp.text, resp.url, resp.headers, trusted=link.trusted)
|
||||
except (HTTPError, URLError, socket.timeout, socket.error, OSError, WindowsError):
|
||||
except requests.Timeout:
|
||||
logger.info("Could not fetch URL %s: timed out", link)
|
||||
if cache is not None:
|
||||
cache.add_page_failure(url, 1)
|
||||
except (requests.HTTPError, URLError, socket.error, OSError, WindowsError):
|
||||
e = sys.exc_info()[1]
|
||||
desc = str(e)
|
||||
if isinstance(e, socket.timeout):
|
||||
log_meth = logger.info
|
||||
level = 1
|
||||
desc = 'timed out'
|
||||
elif isinstance(e, URLError):
|
||||
if isinstance(e, URLError):
|
||||
#ssl/certificate error
|
||||
if hasattr(e, 'reason') and (isinstance(e.reason, ssl.SSLError) or isinstance(e.reason, CertificateError)):
|
||||
desc = 'There was a problem confirming the ssl certificate: %s' % e
|
||||
|
@ -688,7 +688,7 @@ class HTMLPage(object):
|
|||
level = 1
|
||||
else:
|
||||
level = 2
|
||||
elif isinstance(e, HTTPError) and e.response.status_code == 404:
|
||||
elif isinstance(e, requests.HTTPError) and e.response.status_code == 404:
|
||||
## FIXME: notify?
|
||||
log_meth = logger.info
|
||||
level = 2
|
||||
|
@ -700,9 +700,10 @@ class HTMLPage(object):
|
|||
if cache is not None:
|
||||
cache.add_page_failure(url, level)
|
||||
return None
|
||||
if cache is not None:
|
||||
cache.add_page([url, resp.url], inst)
|
||||
return inst
|
||||
else:
|
||||
if cache is not None:
|
||||
cache.add_page([url, resp.url], inst)
|
||||
return inst
|
||||
|
||||
@staticmethod
|
||||
def _get_content_type(url, session=None):
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
from tests.lib import run_pip, reset_env
|
||||
|
||||
|
||||
def test_timeout():
|
||||
reset_env()
|
||||
result = run_pip("--timeout", "0.01", "install", "-vvv", "INITools",
|
||||
expect_error=True,
|
||||
)
|
||||
assert "Could not fetch URL https://pypi.python.org/simple/INITools/: timed out" in result.stdout
|
||||
assert "Could not fetch URL https://pypi.python.org/simple/: timed out" in result.stdout
|
Loading…
Reference in New Issue