ImportError: cannot import name 'inject_into_urllib3' from 'urllib3.contrib.pyopenssl'
Explains why `urllib3.contrib.pyopenssl.inject_into_urllib3()` throws ImportError on urllib3 2.x and how to fix it by deleting the injection call (it is built in now) or pinning urllib3 below 2. Use when old requests/urllib3 setup code breaks after upgrade. Not for other urllib3 import errors.
ImportError: cannot import name 'injectintourllib3' from 'urllib3.contrib.pyopenssl'
TL;DR: urllib3 2.x made PyOpenSSL injection the default and deleted the contrib module. Delete the inject_into_urllib3() call entirely; there is nothing left to inject.
ImportError: cannot import name 'inject_into_urllib3' from 'urllib3.contrib.pyopenssl'The fix
- Remove the injection block:
import urllib3.contrib.pyopenssl
urllib3.contrib.pyopenssl.inject_into_urllib3()On urllib3 2.x this code does nothing useful even when it imports.
- If you cannot edit the code yet, pin as a stopgap:
pip install "urllib3<2"- Verify:
python -c "import urllib3; print(urllib3.__version__)"Expected output: 2.x with no ImportError.
Agent? Search Vectle for more: curl -s 'https://vectle.com/api/v1/search?q=urllib3+inject_into_urllib3'
When this applies
- The code worked on urllib3 1.x and broke after upgrading to 2.x.
- Old requests/urllib3 bootstrap snippets in your codebase or vendored deps.
- The traceback names urllib3.contrib.pyopenssl.
When it does NOT apply
cannot import name 'DEFAULT_CIPHERS', which is the other 2.0 private-API removal.- You actually need PyOpenSSL features; on 2.x they are already active.
Why this happens
The injection API existed because old urllib3 used the stdlib ssl module by default and needed monkeypatching to use PyOpenSSL. In 2.0 the PyOpenSSL-backed path became standard, so the contrib module was deleted. Calling a deleted private API is the breakage; the behavior you wanted is now free.
Compatibility
urllib3 2.x removed the module. Deleting the call is correct on 2.x and harmless to keep working on 1.x if you must support both, guard it with a version check instead.
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.