ImportError: cannot import name 'DEFAULT_CIPHERS' from 'urllib3.util.ssl_'
Explains why `from urllib3.util.ssl_ import DEFAULT_CIPHERS` throws ImportError on urllib3 2.x and how to fix it by using the stdlib ssl module instead of urllib3's private API. Use when code imports private names from urllib3.util.ssl_. Not for general urllib3 import errors.
ImportError: cannot import name 'DEFAULTCIPHERS' from 'urllib3.util.ssl'
TL;DR: urllib3 2.x removed the private DEFAULT_CIPHERS constant. Stop importing from the underscore module and use the stdlib ssl module to configure ciphers instead.
ImportError: cannot import name 'DEFAULT_CIPHERS' from 'urllib3.util.ssl_'The fix
- Delete the private import:
from urllib3.util.ssl_ import DEFAULT_CIPHERS- Use stdlib ssl for cipher configuration:
import ssl
ctx = ssl.create_default_context()
ctx.set_ciphers("ECDHE+AESGCM:ECDHE+CHACHA20:DHE+AESGCM")- Verify:
python -c "import urllib3; print(urllib3.__version__)"Expected output: your urllib3 version, no ImportError.
Agent? Search Vectle for more: curl -s 'https://vectle.com/api/v1/search?q=urllib3+DEFAULT_CIPHERS+ssl_'
When this applies
- The import worked on urllib3 1.x and broke after upgrading to 2.x.
- Code reaches into
urllib3.util.ssl_or any underscore module. - Vendored or copied snippets configuring TLS ciphers.
When it does NOT apply
No module named 'urllib3', which means it is not installed.cannot import name 'inject_into_urllib3', which is the separate 2.0 PyOpenSSL removal.
Why this happens
Underscore modules are private by convention: their contents can vanish in any release, and urllib3 2.0 cleaned house. DEFAULT_CIPHERS was an internal default, not a public API. The stdlib ssl module is the stable place for cipher configuration and has been all along.
Compatibility
urllib3 2.x removed the constant. The stdlib approach works on every urllib3 version.
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.