What this thread does
Do first: Upgrade OpenAI Python SDK to v3.20.0 or a later stable release.
Symptom
FarzamMohammadi reported the following escaping as a bare exception while reading response headers:
ssl.SSLError: [SSL: SSLV3_ALERT_BAD_RECORD_MAC] ssl/tls alert bad record mac (_ssl.c:2657)
The report identifies a regression beginning with 3.14.1 and reproduces it on 3.19.2, where the first attempt fails without the prior connection-error retry behavior.
Other users commented on the issue; the discussion includes rwinkelman, marcuswood-oai.
Cause
The narrowed transport exception handling relied on HTTPX2 mapping every connection failure. Some raw TLS exceptions bypassed that mapping. The merged PR classifies ssl.SSLError and anyio.EndOfStream as connection failures so request retry and wrapping logic can handle them. Merged PR.
Fix
1. Upgrade to the release containing the transport-error shim. Source. 2. Eligible request failures follow the retry budget and become APIConnectionError when that budget is exhausted. The current client also requires the request body to be replayable before retrying. Source. 3. Treat failures during stream consumption separately: the SDK wraps them as connection errors without replaying the stream. Source.
As of November 2026, v3.58.0 source retains this advice. The tagged transport shim still includes raw SSL and end-of-stream exceptions in connection handling.
Fixed in
Fixed in v3.20.0 (released 2026-09-28), the first carrying stable release; PR #3982 merged 2026-09-28.
If it still fails
- This restores SDK handling, rather than removing the underlying TLS failure. Disabled or exhausted retries cannot recover the request. The PR leaves generic application exceptions unchanged, and in-progress streams are not replayed.
Not for: OpenAI Python SDK generic application exceptions, which still propagate unchanged; this change handles unmapped TLS transport failures.
Sources
ssl.SSLErrorduring a request is no longer retried since 3.14.1, FarzamMohammadi, opened 2026-09-26; closed as completed on 2026-09-28: "neither retried nor wrapped inAPIConnectionError."- fix(client): retry unmapped TLS transport errors, marcuswood-oai; merged 2026-09-28 (closed).
- v3.20.0, released 2026-09-28.
- v3.58.0, released 2026-11-23.
- Tagged source: src/openai/_httpx2.py, v3.58.0.
- Tagged source: src/openai/_base_client.py, v3.58.0.
- Tagged source: src/openai/_streaming.py, v3.58.0.
Checked
2026-11-24; read the issue and comments API records, merged PR and changed-file records, fix and v3.58.0 release records, and the tagged source pages listed above; no command was run.
Started from a post by @FarzamMohammadi, packaged by the editor. Original post