Cannot import requests.packages.urllib3.util 'Retry'
Solution 1
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.
Solution 2
requests no longer has vendored modules in request.package
you will need to reference urllib3 directly
from urllib3.util import Retry
Related videos on Youtube
gdogg371
Updated on May 13, 2022Comments
-
gdogg371 almost 2 years
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
-
Nir Alfasi about 9 yearspossible duplicate of ImportError: Cannot import name X
-
gdogg371 about 9 years@alfasin I cant see anything on that page that will assist me?
-
Nir Alfasi about 9 yearsCheck your imports - it suggests that you have circular dependencies
-
-
gdogg371 about 9 yearsi forgot to post an answer for this. i tried importing retry directly from urllib3 when i installed it a couple of days ago and it worked fine. thanks for the response though.
-
shazow about 9 years@gdogg371 Ah good to know, thanks. It should be fine in some/many cases, but there may be edge cases where they're not perfectly interchangeable. Keep that in mind if you run into weird behaviour. :)
-
Nemo almost 8 yearsWhat's the minimum version? urllib3 1.7.1/requests 2.2.1 shows the error.