Jump to solution
Verify

The Fix

Upgrade to version 0.23.2 or later.

Based on closed encode/httpx issue #2491 · 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%.

Jump to Verify Open PR/Commit
@@ -114,7 +114,11 @@ def encode_content( return headers, ByteStream(body) - elif isinstance(content, Iterable): + elif isinstance(content, Iterable) and not isinstance(content, dict): + # `not isinstance(content, dict)` is a bit oddly specific, but it
repro.py
# Look, this error message makes sense... >> httpx.post("https://www.example.com", content=123) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Users/tomchristie/GitHub/encode/httpx/httpx/_api.py", line 304, in post return request( ^^^^^^^^ File "/Users/tomchristie/GitHub/encode/httpx/httpx/_api.py", line 100, in request return client.request( ^^^^^^^^^^^^^^^ File "/Users/tomchristie/GitHub/encode/httpx/httpx/_client.py", line 808, in request request = self.build_request( ^^^^^^^^^^^^^^^^^^^ File "/Users/tomchristie/GitHub/encode/httpx/httpx/_client.py", line 360, in build_request return Request( ^^^^^^^^ File "/Users/tomchristie/GitHub/encode/httpx/httpx/_models.py", line 339, in __init__ headers, stream = encode_request( ^^^^^^^^^^^^^^^ File "/Users/tomchristie/GitHub/encode/httpx/httpx/_content.py", line 205, in encode_request return encode_content(content) ^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/tomchristie/GitHub/encode/httpx/httpx/_content.py", line 130, in encode_content raise TypeError(f"Unexpected type for 'content', {type(content)!r}") TypeError: Unexpected type for 'content', <class 'int'>
verify
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
fix.md
Option A — Upgrade to fixed release\nUpgrade to version 0.23.2 or later.\nWhen NOT to use: This fix is not applicable if the content type is valid and expected by the API.\n\n

Why This Fix Works in Production

  • Trigger: this raises a `RuntimeError: Attempted to send an sync request with an AsyncClient instance.` (full traceback in the `<details>` below.)
  • Mechanism: The content argument was incorrectly accepting a dictionary, leading to a confusing runtime error
  • Why the fix works: Raises a TypeError if a dictionary is passed to the content argument, addressing the confusing error message users encounter. (first fixed release: 0.23.2).
Production impact:
  • 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.9 in real deployments (not just unit tests).
  • The content argument was incorrectly accepting a dictionary, leading to a confusing runtime error
  • Surfaces as: this raises a `RuntimeError: Attempted to send an sync request with an AsyncClient instance.` (full traceback in the `<details>` below.)

Proof / Evidence

  • GitHub issue: #2491
  • Fix PR: https://github.com/encode/httpx/pull/2495
  • First fixed release: 0.23.2
  • 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.30

Discussion

High-signal excerpts from the issue thread (symptoms, repros, edge-cases).

“> I need to interact with an API that accepts DELETE requests requiring JSON content in the body”
@lovelydinosaur · 2022-12-06 · source
“To improve our UX here we ought to be raising a TypeError if a dictionary is passed in the content=..”
@lovelydinosaur · 2022-12-06 · source

Failure Signature (Search String)

  • this raises a `RuntimeError: Attempted to send an sync request with an AsyncClient instance.` (full traceback in the `<details>` below.)

Error Message

Stack trace
error.txt
Error Message ------------- this raises a `RuntimeError: Attempted to send an sync request with an AsyncClient instance.` (full traceback in the `<details>` below.) Am I missing the right way for calling the `request()` method with an `AsyncClient`? <details> <pre> Traceback (most recent call last): File "*******/minimal.py", line 14, in <module> asyncio.run(test_request_method()) File "/opt/homebrew/Cellar/[email protected]/3.9.13_3/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/runners.py", line 44, in run return loop.run_until_complete(main) File "/opt/homebrew/Cellar/[email protected]/3.9.13_3/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 647, in run_until_complete return future.result() File "*********minimal.py", line 11, in test_request_method response = await ac.request(method="DELETE", url="/", content={"foo": "bar"}) File "*********/lib/python3.9/site-packages/httpx/_client.py", line 1527, in request return await self.send(request, auth=auth, follow_redirects=follow_redirects) File "*********/lib/python3.9/site-packages/httpx/_client.py", line 1614, in send response = await self._send_handling_auth( File "*********/lib/python3.9/site-packages/httpx/_client.py", line 1642, in _send_handling_auth response = await self._send_handling_redirects( File "*********/lib/python3.9/site-packages/httpx/_client.py", line 1 ... (truncated) ...

Minimal Reproduction

repro.py
# Look, this error message makes sense... >> httpx.post("https://www.example.com", content=123) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Users/tomchristie/GitHub/encode/httpx/httpx/_api.py", line 304, in post return request( ^^^^^^^^ File "/Users/tomchristie/GitHub/encode/httpx/httpx/_api.py", line 100, in request return client.request( ^^^^^^^^^^^^^^^ File "/Users/tomchristie/GitHub/encode/httpx/httpx/_client.py", line 808, in request request = self.build_request( ^^^^^^^^^^^^^^^^^^^ File "/Users/tomchristie/GitHub/encode/httpx/httpx/_client.py", line 360, in build_request return Request( ^^^^^^^^ File "/Users/tomchristie/GitHub/encode/httpx/httpx/_models.py", line 339, in __init__ headers, stream = encode_request( ^^^^^^^^^^^^^^^ File "/Users/tomchristie/GitHub/encode/httpx/httpx/_content.py", line 205, in encode_request return encode_content(content) ^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/tomchristie/GitHub/encode/httpx/httpx/_content.py", line 130, in encode_content raise TypeError(f"Unexpected type for 'content', {type(content)!r}") TypeError: Unexpected type for 'content', <class 'int'>

Environment

  • Python: 3.9

What Broke

Users encountered a runtime error when sending a DELETE request with incorrect content type.

Why It Broke

The content argument was incorrectly accepting a dictionary, leading to a confusing runtime error

Fix Options (Details)

Option A — Upgrade to fixed release Safe default (recommended)

Upgrade to version 0.23.2 or later.

When NOT to use: This fix is not applicable if the content type is valid and expected by the API.

Use when you can deploy the upstream fix. It is usually lower-risk than long-lived workarounds.

Fix reference: https://github.com/encode/httpx/pull/2495

First fixed release: 0.23.2

Last verified: 2026-02-09. Validate in your environment.

Get updates

We publish verified fixes weekly. No spam.

Subscribe

When NOT to Use This Fix

  • This fix is not applicable if the content type is valid and expected by the API.

Verify Fix

verify
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.

Version Compatibility Table

VersionStatus
0.23.2 Fixed

Related Issues

No related fixes found.

Sources

We don’t republish the full GitHub discussion text. Use the links above for context.