The Fix
pip install urllib3==2.6.0
Based on closed urllib3/urllib3 issue #3700 · PR/commit linked
Production note: Most teams hit this during upgrades or environment changes. Roll out with a canary and smoke critical endpoints (health, OpenAPI/docs) before 100%.
@@ -0,0 +1 @@
@@ -0,0 +1 @@
+Fixed set ``ssl.SSLContext.keylog_filename`` with expanded environment variable.
diff --git a/src/urllib3/util/ssl_.py b/src/urllib3/util/ssl_.py
index 37794d213a..56fe9093ad 100644
import platform
import ssl
import urllib3
print("OS", platform.platform())
print("Python", platform.python_version())
print(ssl.OPENSSL_VERSION)
print("urllib3", urllib3.__version__)
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
Option A — Upgrade to fixed release\npip install urllib3==2.6.0\nWhen NOT to use: This fix is not applicable if the environment variable is not needed.\n\n
Why This Fix Works in Production
- Trigger: context.keylog_filename = sslkeylogfile
- Mechanism: Environment variable SSLKEYLOGFILE was not resolving nested variables correctly on Windows
- Why the fix works: Expands the environment variable of SSLKEYLOGFILE to resolve paths correctly on Windows. (first fixed release: 2.6.0).
- If left unfixed, the same config can fail only in production (env differences), causing startup failures or partial feature outages.
Why This Breaks in Prod
- Shows up under Python 3.12 in real deployments (not just unit tests).
- Environment variable SSLKEYLOGFILE was not resolving nested variables correctly on Windows
- Surfaces as: File "C:\Program Files\Python312\Lib\site-packages\urllib3\util\ssl_.py", line 369, in create_urllib3_context
Proof / Evidence
- GitHub issue: #3700
- Fix PR: https://github.com/urllib3/urllib3/pull/3705
- First fixed release: 2.6.0
- Reproduced locally: No (not executed)
- Last verified: 2026-02-09
- Confidence: 0.85
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.66
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“We should use an already implemented function for resolving the environment variables, like os.path.expandvars()?”
“I have searched a little deeper and made tests using the ExpandEnvironmentStrings* functions from userenv.h and those functions are not recursive”
Failure Signature (Search String)
- context.keylog_filename = sslkeylogfile
Error Message
Stack trace
Error Message
-------------
File "C:\Program Files\Python312\Lib\site-packages\urllib3\util\ssl_.py", line 369, in create_urllib3_context
context.keylog_filename = sslkeylogfile
^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: '%USERPROFILE%\\AppData\\ssl-keys.log'
Minimal Reproduction
import platform
import ssl
import urllib3
print("OS", platform.platform())
print("Python", platform.python_version())
print(ssl.OPENSSL_VERSION)
print("urllib3", urllib3.__version__)
Environment
- Python: 3.12
- urllib3: 2.5.0
What Broke
Requests fail with FileNotFoundError due to unresolved SSLKEYLOGFILE path.
Why It Broke
Environment variable SSLKEYLOGFILE was not resolving nested variables correctly on Windows
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
pip install urllib3==2.6.0
Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.
Fix reference: https://github.com/urllib3/urllib3/pull/3705
First fixed release: 2.6.0
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- This fix is not applicable if the environment variable is not needed.
Verify Fix
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
Did This Fix Work in Your Case?
Quick signal helps us prioritize which fixes to verify and improve.
Prevention
- Add a CI check that diffs key outputs after upgrades (OpenAPI schema snapshots, JSON payload shapes, CLI output).
- Upgrade behind a canary and run integration tests against the canary before 100% rollout.
- Add a TLS smoke test that performs a real handshake in CI (include CA bundle validation and hostname checks).
- Alert on handshake failures by error string and endpoint to catch cert/CA changes quickly.
Version Compatibility Table
| Version | Status |
|---|---|
| 2.6.0 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.