Requests: TypeError: unsupported operand type(s) for -=: 'Retry' and 'int'

Created on 8 Sep 2016  ·  10Comments  ·  Source: psf/requests

Description:

I've been trying to install pip into an virtualenv as part of building a Linux package. When installing pip, it always gives me the same error in requests and fails. I've seen the same error in shazow/urllib3#567, but the fix there doesn't seem to have worked for me.

What I've run:

dh build-arch -S --buildsystem=dh_virtualenv --setuptools --python=python2.7 --no-test
   dh_testdir -a -O-S -O--buildsystem=dh_virtualenv -O--setuptools -O--python=python2.7 -O--no-test
   dh_update_autotools_config -a -O-S -O--buildsystem=dh_virtualenv -O--setuptools -O--python=python2.7 -O--no-test
   dh_auto_configure -a -O-S -O--buildsystem=dh_virtualenv -O--setuptools -O--python=python2.7 -O--no-test
    mkdir -p build/usr/lib/mycroft-core
   dh_auto_build -a -O-S -O--buildsystem=dh_virtualenv -O--setuptools -O--python=python2.7 -O--no-test
    cd build
    virtualenv --always-copy --clear /«PKGBUILDDIR»/build/usr/lib/mycroft-core
Not deleting /«PKGBUILDDIR»/build/usr/lib/mycroft-core/bin
New python executable in /«PKGBUILDDIR»/build/usr/lib/mycroft-core/bin/python2
Also creating executable in /«PKGBUILDDIR»/build/usr/lib/mycroft-core/bin/python
Installing setuptools, pkg_resources, pip, wheel...
  Complete output from command /build/mycroft-core-...oft-core/bin/python2 - setuptools pkg_resources pip wheel:
  Collecting setuptools
Exception:
Traceback (most recent call last):
  File "/usr/share/python-wheels/pip-8.1.1-py2.py3-none-any.whl/pip/basecommand.py", line 209, in main
    status = self.run(options, args)
  File "/usr/share/python-wheels/pip-8.1.1-py2.py3-none-any.whl/pip/commands/install.py", line 328, in run
    wb.build(autobuilding=True)
  File "/usr/share/python-wheels/pip-8.1.1-py2.py3-none-any.whl/pip/wheel.py", line 748, in build
    self.requirement_set.prepare_files(self.finder)
  File "/usr/share/python-wheels/pip-8.1.1-py2.py3-none-any.whl/pip/req/req_set.py", line 360, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "/usr/share/python-wheels/pip-8.1.1-py2.py3-none-any.whl/pip/req/req_set.py", line 512, in _prepare_file
    finder, self.upgrade, require_hashes)
  File "/usr/share/python-wheels/pip-8.1.1-py2.py3-none-any.whl/pip/req/req_install.py", line 273, in populate_link
    self.link = finder.find_requirement(self, upgrade)
  File "/usr/share/python-wheels/pip-8.1.1-py2.py3-none-any.whl/pip/index.py", line 442, in find_requirement
    all_candidates = self.find_all_candidates(req.name)
  File "/usr/share/python-wheels/pip-8.1.1-py2.py3-none-any.whl/pip/index.py", line 400, in find_all_candidates
    for page in self._get_pages(url_locations, project_name):
  File "/usr/share/python-wheels/pip-8.1.1-py2.py3-none-any.whl/pip/index.py", line 545, in _get_pages
    page = self._get_page(location)
  File "/usr/share/python-wheels/pip-8.1.1-py2.py3-none-any.whl/pip/index.py", line 648, in _get_page
    return HTMLPage.get_page(link, session=self.session)
  File "/usr/share/python-wheels/pip-8.1.1-py2.py3-none-any.whl/pip/index.py", line 757, in get_page
    "Cache-Control": "max-age=600",
  File "/«PKGBUILDDIR»/build/usr/lib/mycroft-core/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/share/python-wheels/pip-8.1.1-py2.py3-none-any.whl/pip/download.py", line 378, in request
    return super(PipSession, self).request(method, url, *args, **kwargs)
  File "/«PKGBUILDDIR»/build/usr/lib/mycroft-core/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 "/«PKGBUILDDIR»/build/usr/lib/mycroft-core/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 "/«PKGBUILDDIR»/build/usr/lib/mycroft-core/share/python-wheels/CacheControl-0.11.5-py2.py3-none-any.whl/cachecontrol/adapter.py", line 46, in send
    resp = super(CacheControlAdapter, self).send(request, **kw)
  File "/«PKGBUILDDIR»/build/usr/lib/mycroft-core/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/adapters.py", line 376, in send
Traceback (most recent call last):
    timeout=timeout
  File "/«PKGBUILDDIR»/build/usr/lib/mycroft-core/share/python-wheels/urllib3-1.13.1-py2.py3-none-any.whl/urllib3/connectionpool.py", line 610, in urlopen
  File "/usr/lib/python3/dist-packages/virtualenv.py", line 2363, in <module>
    _stacktrace=sys.exc_info()[2])
  File "/«PKGBUILDDIR»/build/usr/lib/mycroft-core/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'
----------------------------------------
...Installing setuptools, pkg_resources, pip, wheel...done.
    main()
  File "/usr/lib/python3/dist-packages/virtualenv.py", line 719, in main
    symlink=options.symlink)
  File "/usr/lib/python3/dist-packages/virtualenv.py", line 988, in create_environment
    download=download,
  File "/usr/lib/python3/dist-packages/virtualenv.py", line 918, in install_wheel
    call_subprocess(cmd, show_stdout=False, extra_env=env, stdin=SCRIPT)
  File "/usr/lib/python3/dist-packages/virtualenv.py", line 812, in call_subprocess
    % (cmd_desc, proc.returncode))
OSError: Command /build/mycroft-core-...oft-core/bin/python2 - setuptools pkg_resources pip wheel failed with error code 2
Running virtualenv with interpreter /usr/bin/python2
dh_auto_build: virtualenv --always-copy --clear /«PKGBUILDDIR»/build/usr/lib/mycroft-core returned exit code 1
    cd /«PKGBUILDDIR»
debian/rules:10: recipe for target 'build-arch' failed
make: *** [build-arch] Error 25
dpkg-buildpackage: error: debian/rules build-arch gave error exit status 2

`

Most helpful comment

Once you have installed via sudo with pip, all bets are off. Ubuntu's built in packages make substantial modifications to both pip and Requests, which includes removing stuff. If you ever mix the Ubuntu packages with the pip ones, a mess will ensue and it basically permanently damages them unless you can reinstall from Ubuntu's sources.

You have to start with a virtualenv if you want pip, otherwise restrict yourself to apt-get.

All 10 comments

In this instance, this is almost certainly Debian/Ubuntu's problem and not ours: you appear to be using Debian/Ubuntu's packages. That means you need to follow up with Debian/Ubuntu in the first case, as they maintain several patches and are responsible for supporting those packages in their system. If they find that the problem can be reproduced using the source that we distributed to them, then we'll accept the bug report here.

Sorry we can't be more helpful!

@Lukasa could you give any pointers to debug this? I'm getting the same error when I try to use pip. I'm trying to understand what's going on, but I don't know where to start

@elopio The first question is to work out what OS you're on and where your packages have come from. How did you get pip? How did you get Requests? Where are they coming from in your OS?

I'm using ubuntu core 16 on beaglebone black. I installed pip from the 16.04 archive.
I added a debug print and found that my board can't ping pypi.python.org. There's something weird with the dns, so I added the ip to /etc/hosts, and the error no longer appears.

So that has masked the underlying problem. You say you got pip from 16.04: did you install Requests from anywhere else?

I tried with the one installed by pip with sudo, the one from the ubuntu archive, and the one installed in a virtualenv. py2 and py3. They all failed the same way:

  File "/home/ubuntu/.ENV/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/adapters.py", line 376, in send
    timeout=timeout
  File "/home/ubuntu/.ENV/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 "/home/ubuntu/.ENV/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'

Once you have installed via sudo with pip, all bets are off. Ubuntu's built in packages make substantial modifications to both pip and Requests, which includes removing stuff. If you ever mix the Ubuntu packages with the pip ones, a mess will ensue and it basically permanently damages them unless you can reinstall from Ubuntu's sources.

You have to start with a virtualenv if you want pip, otherwise restrict yourself to apt-get.

@Lukasa can you try to explain this to me? I am trying to install a virtualenv, and it the virtualenv is trying to install pip, and I get this error. If I install pip first, I still get this error. Should I install pip first, or virtualenv first?

@cfossace It depends how you're installing them. On Linux, you should do apt-get install python-virtualenv (or the yum equivalent), and then use virtualenv. Don't install pip or virtualenv any other way. At that point, when you create virtualenvs you will be able to have isolated Python environments that don't affect your system.

Thank you! I didn't realize python-virtualenv was a package.

On Fri, Aug 25, 2017 at 3:28 AM, Cory Benfield notifications@github.com
wrote:

@cfossace
https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcfossace&data=02%7C01%7Ccfossace%40villanova.edu%7C0bfb1a2ead2e44a9108108d4eb8ae7be%7C765a8de5cf9444f09cafae5bf8cfa366%7C0%7C0%7C636392429213691672&sdata=8NFbq8D6Bdu%2BnTocxi%2BbAJaczOjqqQ8taAJI3t5grQ0%3D&reserved=0
It depends how you're installing them. On Linux, you should do apt-get
install python-virtualenv (or the yum equivalent), and then use virtualenv.
Don't install pip or virtualenv any other way. At that point, when you
create virtualenvs you will be able to have isolated Python environments
that don't affect your system.


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Frequests%2Frequests%2Fissues%2F3560%23issuecomment-324844916&data=02%7C01%7Ccfossace%40villanova.edu%7C0bfb1a2ead2e44a9108108d4eb8ae7be%7C765a8de5cf9444f09cafae5bf8cfa366%7C0%7C0%7C636392429213691672&sdata=uO7pfPYNAEXkKHZobD7IErbHrRSZwG5ZufkVwbhjdK0%3D&reserved=0,
or mute the thread
https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAIOMc9pD6XN47SKmDBX8HEGoJ7kBcCb3ks5sbnemgaJpZM4J3bzG&data=02%7C01%7Ccfossace%40villanova.edu%7C0bfb1a2ead2e44a9108108d4eb8ae7be%7C765a8de5cf9444f09cafae5bf8cfa366%7C0%7C0%7C636392429213691672&sdata=0wYRDY73g2VcL7lRMaKxwTwcF0OhY0ATCCXIb%2FLvsU8%3D&reserved=0
.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jakul picture jakul  ·  3Comments

thadeusb picture thadeusb  ·  3Comments

eromoe picture eromoe  ·  3Comments

ghtyrant picture ghtyrant  ·  3Comments

NoahCardoza picture NoahCardoza  ·  4Comments