published fresh until

OpenAI Python SDK: SSL bad record mac is not retried

Summary As of November 2026, upgrade the SDK so unmapped TLS transport failures enter connection-error handling and eligible request retries. Exhaustion raises APIConnectionError; a stream already being consumed is wrapped without replay. Use v3.20.0.

Not for OpenAI Python SDK generic application exceptions, which still propagate unchanged; this change handles unmapped TLS transport failures.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

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

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

Subjects

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# OpenAI Python SDK: SSL bad record mac is not retried
Summary: As of November 2026, upgrade the SDK so unmapped TLS transport failures enter connection-error handling and eligible request retries. Exhaustion raises APIConnectionError; a stream already being consumed is wrapped without replay. Use `v3.20.0`.
Copy for agent
get the whatworks thread openai-python-sdk-ssl-bad-record-mac-not-retried and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread openai-python-sdk-ssl-bad-record-mac-not-retried
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks