Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot import requests.packages.urllib3.util 'Retry'

I am using Python 2.7 64 bit on Windows 8. I have Requests version 2.3 installed. I am trying to run this import statement as part of bringing in number of retries within my code:

from requests.packages.urllib3.util import Retry

I have urllib3 installed also (I've just installed it now via Pip). I am getting the error message:

Traceback (most recent call last):
  File "C:\Python27\counter.py", line 3, in <module>
    from requests.packages.urllib3.util import Retry
ImportError: cannot import name Retry

Can anyone tell me why this is? Are there any other dependencies I am unaware of to run this line of code successfully?

Thanks

like image 457
gdogg371 Avatar asked Mar 06 '15 17:03

gdogg371


2 Answers

You might need a newer version of Requests. I just tried it with v2.5.1:

from requests.packages.urllib3.util import Retry

Seems to work. FYI: The latest version is v2.5.3, worth upgrading.

Also if you have a reasonably recent version of urllib3 installed separately, this should also work:

from urllib3.util import Retry

Unfortunately we check the specific isinstance type of Retry in PoolManager and ConnectionPool, so the two types of Retry objects might not be perfectly interchangeable. (If anyone wants to fix this, I'd be +1 on a PR.)

For now, if you're intending on using the Retry object with the requests version of urllib3, you'll need to import it from there directly.

like image 191
shazow Avatar answered Nov 16 '22 02:11

shazow


requests no longer has vendored modules in request.package

you will need to reference urllib3 directly

from urllib3.util import Retry
like image 18
jpoehnelt Avatar answered Nov 16 '22 04:11

jpoehnelt