urllib3/util/retry.py broke on passing invalid type

Bug #1586859 reported by John Weng
24
This bug affects 5 people
Affects Status Importance Assigned to Milestone
python-pip (Debian)
Fix Released
Unknown
python-pip (Ubuntu)
Fix Released
Undecided
Unassigned

Bug Description

Hi,

I was running "pip wheel --wheel-dir $WHEELHOUSE --index-url $PYPI_SERVER --requirement $2 --find-links $WHEELHOUSE" and receiving below stacktrace with package python-pip-whl version 8.1.1-2ubuntu0.1 in Ubuntu 16.04 (Python 3.5). The old release 8.1.1-2 works all good.

Collecting repoze.lru==0.6 (from -r ./python-pip-freeze.txt (line 39))
Exception:
Traceback (most recent call last):
  File "/usr/local/dev-venv/share/python-wheels/urllib3-1.13.1-py2.py3-none-any.whl/urllib3/connection.py", line 137, in _new_conn
    (self.host, self.port), self.timeout, **extra_kw)
  File "/usr/local/dev-venv/share/python-wheels/urllib3-1.13.1-py2.py3-none-any.whl/urllib3/util/connection.py", line 91, in create_connection
    raise err
  File "/usr/local/dev-venv/share/python-wheels/urllib3-1.13.1-py2.py3-none-any.whl/urllib3/util/connection.py", line 81, in create_connection
    sock.connect(sa)
OSError: [Errno 101] Network is unreachable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/dev-venv/share/python-wheels/urllib3-1.13.1-py2.py3-none-any.whl/urllib3/connectionpool.py", line 560, in urlopen
    body=body, headers=headers)
  File "/usr/local/dev-venv/share/python-wheels/urllib3-1.13.1-py2.py3-none-any.whl/urllib3/connectionpool.py", line 354, in _make_request
    conn.request(method, url, **httplib_request_kw)
  File "/usr/lib/python3.5/http/client.py", line 1106, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib/python3.5/http/client.py", line 1151, in _send_request
    self.endheaders(body)
  File "/usr/lib/python3.5/http/client.py", line 1102, in endheaders
    self._send_output(message_body)
  File "/usr/lib/python3.5/http/client.py", line 934, in _send_output
    self.send(msg)
  File "/usr/lib/python3.5/http/client.py", line 877, in send
    self.connect()
  File "/usr/local/dev-venv/share/python-wheels/urllib3-1.13.1-py2.py3-none-any.whl/urllib3/connection.py", line 162, in connect
    conn = self._new_conn()
  File "/usr/local/dev-venv/share/python-wheels/urllib3-1.13.1-py2.py3-none-any.whl/urllib3/connection.py", line 146, in _new_conn
    self, "Failed to establish a new connection: %s" % e)
pip._vendor.requests.packages.urllib3.exceptions.NewConnectionError: <pip._vendor.requests.packages.urllib3.connection.HTTPConnection object at 0x7fde8f0e8358>: Failed to establish a new connection: [Errno 101] Network is unreachable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/dev-venv/lib/python3.5/site-packages/pip/basecommand.py", line 209, in main
    status = self.run(options, args)
  File "/usr/local/dev-venv/lib/python3.5/site-packages/pip/commands/wheel.py", line 195, in run
    if not wb.build():
  File "/usr/local/dev-venv/lib/python3.5/site-packages/pip/wheel.py", line 748, in build
    self.requirement_set.prepare_files(self.finder)
  File "/usr/local/dev-venv/lib/python3.5/site-packages/pip/req/req_set.py", line 360, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "/usr/local/dev-venv/lib/python3.5/site-packages/pip/req/req_set.py", line 512, in _prepare_file
    finder, self.upgrade, require_hashes)
  File "/usr/local/dev-venv/lib/python3.5/site-packages/pip/req/req_install.py", line 273, in populate_link
    self.link = finder.find_requirement(self, upgrade)
  File "/usr/local/dev-venv/lib/python3.5/site-packages/pip/index.py", line 442, in find_requirement
    all_candidates = self.find_all_candidates(req.name)
  File "/usr/local/dev-venv/lib/python3.5/site-packages/pip/index.py", line 400, in find_all_candidates
    for page in self._get_pages(url_locations, project_name):
  File "/usr/local/dev-venv/lib/python3.5/site-packages/pip/index.py", line 545, in _get_pages
    page = self._get_page(location)
  File "/usr/local/dev-venv/lib/python3.5/site-packages/pip/index.py", line 648, in _get_page
    return HTMLPage.get_page(link, session=self.session)
  File "/usr/local/dev-venv/lib/python3.5/site-packages/pip/index.py", line 757, in get_page
    "Cache-Control": "max-age=600",
  File "/usr/local/dev-venv/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/sessions.py", line 480, in get
    return self.request('GET', url, **kwargs)
  File "/usr/local/dev-venv/lib/python3.5/site-packages/pip/download.py", line 378, in request
    return super(PipSession, self).request(method, url, *args, **kwargs)
  File "/usr/local/dev-venv/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/sessions.py", line 468, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/local/dev-venv/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/sessions.py", line 597, in send
    history = [resp for resp in gen] if allow_redirects else []
  File "/usr/local/dev-venv/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/sessions.py", line 597, in <listcomp>
    history = [resp for resp in gen] if allow_redirects else []
  File "/usr/local/dev-venv/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/sessions.py", line 195, in resolve_redirects
    **adapter_kwargs
  File "/usr/local/dev-venv/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/sessions.py", line 576, in send
    r = adapter.send(request, **kwargs)
  File "/usr/local/dev-venv/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/adapters.py", line 376, in send
    timeout=timeout
  File "/usr/local/dev-venv/share/python-wheels/urllib3-1.13.1-py2.py3-none-any.whl/urllib3/connectionpool.py", line 610, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/usr/local/dev-venv/share/python-wheels/urllib3-1.13.1-py2.py3-none-any.whl/urllib3/util/retry.py", line 228, in increment
    total -= 1
TypeError: unsupported operand type(s) for -=: 'Retry' and 'int'

Revision history for this message
John Weng (wengcsyz) wrote :

Forgot to say "Thanks" ;)

Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in python-pip (Ubuntu):
status: New → Confirmed
Revision history for this message
monkeybrain2012 (kammon101) wrote :

I am having exactly the same problem is Ubuntu 17.10. Apparently it happens when network connectivity is poor and pip attempts to retry download and some Debian/Ubuntu patch in pip mess up the retry logic.
https://github.com/pypa/pip/issues/3943
https://github.com/pypa/pip/issues/4779
https://github.com/pypa/pip/issues/4847

Revision history for this message
Glenn Washburn (crass) wrote :

I've hit this bug on ubuntu 16.10 with python-pip version 8.1.2-2ubuntu0.1 when trying to create a virtualenv while disconnected from the network. After upgrading to python-pip version 9.0.1-2.3 from ubuntu 18.04, this behavior disappeared. So I believe this problem resolved.

I've attached a python script that will work in python 2 or 3 which reproduces this bug on affected systems for verifying that this issue has been fixed.

Revision history for this message
Kai Kasurinen (kai-kasurinen) wrote :

Fixed in version python-pip/20.0.2-3

Changed in python-pip (Ubuntu):
status: Confirmed → Fix Released
Changed in python-pip (Debian):
status: Unknown → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Duplicates of this bug

Other bug subscribers

Related questions

Remote bug watches

Bug watches keep track of this bug in other bug trackers.