Jump to solution
Verify

The Fix

Upgrade to version 0.23.0 or later.

Based on closed encode/httpx issue #2050 · 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
@@ -8,8 +8,10 @@ import pygments.util import rich.console +import rich.markup import rich.progress import rich.syntax
repro.py
$ httpx https://cataas.com/cat HTTP/1.1 200 OK Server: nginx/1.12.2 Date: Thu, 27 Jan 2022 11:19:17 GMT Content-Type: image/jpeg Content-Length: 40849 Connection: keep-alive Access-Control-Allow-Origin: * Access-Control-Allow-Headers: X-Requested-With, Content-Type, Accept, Origin, Authorization Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS Cache-Control: public, max-age=30 ETag: 1643256053593 Traceback (most recent call last): File "venv/bin/httpx", line 11, in <module> load_entry_point('httpx', 'console_scripts', 'httpx')() File "/Users/tomchristie/GitHub/encode/httpx/venv/lib/python3.7/site-packages/click/core.py", line 1128, in __call__ return self.main(*args, **kwargs) File "/Users/tomchristie/GitHub/encode/httpx/venv/lib/python3.7/site-packages/click/core.py", line 1053, in main rv = self.invoke(ctx) File "/Users/tomchristie/GitHub/encode/httpx/venv/lib/python3.7/site-packages/click/core.py", line 1395, in invoke return ctx.invoke(self.callback, **ctx.params) File "/Users/tomchristie/GitHub/encode/httpx/venv/lib/python3.7/site-packages/click/core.py", line 754, in invoke return __callback(*args, **kwargs) File "/Users/tomchristie/GitHub/encode/httpx/httpx/_main.py", line 486, in main print_response(response) File "/Users/tomchristie/GitHub/encode/httpx/httpx/_main.py", line 176, in print_response console.print(response.text) File "/Users/tomchristie/GitHub/encode/httpx/venv/lib/python3.7/site-packages/rich/console.py", line 1602, in print highlight=highlight, File "/Users/tomchristie/GitHub/encode/httpx/venv/lib/python3.7/site-packages/rich/console.py", line 1460, in _collect_renderables renderable, emoji=emoji, markup=markup, highlighter=_highlighter File "/Users/tomchristie/GitHub/encode/httpx/venv/lib/python3.7/site-packages/rich/console.py", line 1355, in render_str emoji_variant=self._emoji_variant, File "/Users/tomchristie/GitHub/encode/httpx/venv/lib/python3.7/site-packages/rich/markup.py", line 161, in render ) from None rich.errors.MarkupError: closing tag '[/�$B����c}Nʌ��W�a�����}O��W��4Q;!�����0]' at position 3761 doesn't match any open tag
verify
Re-run: httpx https://cataas.com/cat
fix.md
Option A — Upgrade to fixed release\nUpgrade to version 0.23.0 or later.\nWhen NOT to use: Do not apply this fix if the output does not contain markup that needs escaping.\n\n

Why This Fix Works in Production

  • Trigger: $ httpx https://cataas.com/cat
  • Mechanism: Console output raises exceptions due to unescaped markup interpreted by rich
  • Why the fix works: Fixes console markup escaping issue to prevent exceptions when rendering output in the CLI. (first fixed release: 0.23.0).
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.7 in real deployments (not just unit tests).
  • Console output raises exceptions due to unescaped markup interpreted by rich
  • Surfaces as: $ httpx https://cataas.com/cat

Proof / Evidence

  • GitHub issue: #2050
  • Fix PR: https://github.com/encode/httpx/pull/1866
  • First fixed release: 0.23.0
  • Reproduced locally: No (not executed)
  • Last verified: 2026-02-08
  • Confidence: 0.85
  • Did this fix it?: Yes (upstream fix exists)
  • Own content ratio: 0.25

Discussion

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

“Resolved in #1866 (I added one additional escape in there)”
@lovelydinosaur · 2022-02-04 · confirmation · source

Failure Signature (Search String)

  • $ httpx https://cataas.com/cat

Error Message

Stack trace
error.txt
Error Message ------------- $ httpx https://cataas.com/cat HTTP/1.1 200 OK Server: nginx/1.12.2 Date: Thu, 27 Jan 2022 11:19:17 GMT Content-Type: image/jpeg Content-Length: 40849 Connection: keep-alive Access-Control-Allow-Origin: * Access-Control-Allow-Headers: X-Requested-With, Content-Type, Accept, Origin, Authorization Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS Cache-Control: public, max-age=30 ETag: 1643256053593 Traceback (most recent call last): File "venv/bin/httpx", line 11, in <module> load_entry_point('httpx', 'console_scripts', 'httpx')() File "/Users/tomchristie/GitHub/encode/httpx/venv/lib/python3.7/site-packages/click/core.py", line 1128, in __call__ return self.main(*args, **kwargs) File "/Users/tomchristie/GitHub/encode/httpx/venv/lib/python3.7/site-packages/click/core.py", line 1053, in main rv = self.invoke(ctx) File "/Users/tomchristie/GitHub/encode/httpx/venv/lib/python3.7/site-packages/click/core.py", line 1395, in invoke return ctx.invoke(self.callback, **ctx.params) File "/Users/tomchristie/GitHub/encode/httpx/venv/lib/python3.7/site-packages/click/core.py", line 754, in invoke return __callback(*args, **kwargs) File "/Users/tomchristie/GitHub/encode/httpx/httpx/_main.py", line 486, in main print_response(response) File "/Users/tomchristie/GitHub/encode/httpx/httpx/_main.py", line 176, in print_response console.print(re ... (truncated) ...

Minimal Reproduction

repro.py
$ httpx https://cataas.com/cat HTTP/1.1 200 OK Server: nginx/1.12.2 Date: Thu, 27 Jan 2022 11:19:17 GMT Content-Type: image/jpeg Content-Length: 40849 Connection: keep-alive Access-Control-Allow-Origin: * Access-Control-Allow-Headers: X-Requested-With, Content-Type, Accept, Origin, Authorization Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS Cache-Control: public, max-age=30 ETag: 1643256053593 Traceback (most recent call last): File "venv/bin/httpx", line 11, in <module> load_entry_point('httpx', 'console_scripts', 'httpx')() File "/Users/tomchristie/GitHub/encode/httpx/venv/lib/python3.7/site-packages/click/core.py", line 1128, in __call__ return self.main(*args, **kwargs) File "/Users/tomchristie/GitHub/encode/httpx/venv/lib/python3.7/site-packages/click/core.py", line 1053, in main rv = self.invoke(ctx) File "/Users/tomchristie/GitHub/encode/httpx/venv/lib/python3.7/site-packages/click/core.py", line 1395, in invoke return ctx.invoke(self.callback, **ctx.params) File "/Users/tomchristie/GitHub/encode/httpx/venv/lib/python3.7/site-packages/click/core.py", line 754, in invoke return __callback(*args, **kwargs) File "/Users/tomchristie/GitHub/encode/httpx/httpx/_main.py", line 486, in main print_response(response) File "/Users/tomchristie/GitHub/encode/httpx/httpx/_main.py", line 176, in print_response console.print(response.text) File "/Users/tomchristie/GitHub/encode/httpx/venv/lib/python3.7/site-packages/rich/console.py", line 1602, in print highlight=highlight, File "/Users/tomchristie/GitHub/encode/httpx/venv/lib/python3.7/site-packages/rich/console.py", line 1460, in _collect_renderables renderable, emoji=emoji, markup=markup, highlighter=_highlighter File "/Users/tomchristie/GitHub/encode/httpx/venv/lib/python3.7/site-packages/rich/console.py", line 1355, in render_str emoji_variant=self._emoji_variant, File "/Users/tomchristie/GitHub/encode/httpx/venv/lib/python3.7/site-packages/rich/markup.py", line 161, in render ) from None rich.errors.MarkupError: closing tag '[/�$B����c}Nʌ��W�a�����}O��W��4Q;!�����0]' at position 3761 doesn't match any open tag

Environment

  • Python: 3.7

What Broke

CLI crashes when rendering unescaped response text containing markup.

Why It Broke

Console output raises exceptions due to unescaped markup interpreted by rich

Fix Options (Details)

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

Upgrade to version 0.23.0 or later.

When NOT to use: Do not apply this fix if the output does not contain markup that needs escaping.

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/1866

First fixed release: 0.23.0

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

Get updates

We publish verified fixes weekly. No spam.

Subscribe

When NOT to Use This Fix

  • Do not apply this fix if the output does not contain markup that needs escaping.

Verify Fix

verify
Re-run: httpx https://cataas.com/cat

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.0 Fixed

Related Issues

No related fixes found.

Sources

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