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

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

from requests.packages.urllib3.util import Retry 

I also have urllib3 installed (I just installed it via Pip). I get an 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 someone tell me why this is? Are there any other dependencies that I don’t know about to successfully run this line of code?

thanks

+7
python python-requests urllib3
source share
2 answers

You may need a newer version of the request. I just tried this with v2.5.1:

 from requests.packages.urllib3.util import Retry 

It seems to need work. FYI: latest version v2.5.3, worth updating.

In addition, if you have a fairly recent version of urllib3 installed separately, this should also work:

 from urllib3.util import Retry 

Unfortunately, we are checking the specific type of isinstance Retry in PoolManager and ConnectionPool , so the two types of Retry objects may not be completely interchangeable. (If someone wants to fix this, I would add +1 to PR.)

Now, if you plan to use the Retry object with requests version of urllib3 , you will need to import it directly from it.

+6
source share

requests no longer have provider modules in request.package

you will need to reference urllib3 directly

+1
source share

All Articles