The Fix
Upgrade to version 0.14.0 or later.
Based on closed encode/httpx issue #846 · 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%.
@@ -66,13 +66,10 @@ def __init__(
timeout: TimeoutTypes = DEFAULT_TIMEOUT_CONFIG,
max_redirects: int = DEFAULT_MAX_REDIRECTS,
- base_url: URLTypes = None,
+ base_url: URLTypes = "",
trust_env: bool = True,
Python 3.8.1 (default, Jan 10 2020, 09:36:37)
[Clang 11.0.0 (clang-1100.0.33.16)] on darwin
>> import httpx
>> http_client = httpx.Client(base_url="https://example.com/api/v1")
>> append = http_client.get("endpoint")
>> append.url
URL('https://example.com/api/endpoint')
>> replace = http_client.get("/api/v2/new")
>> replace.url
URL('https://example.com/api/v2/new')
>> httpx.__version__
'0.11.1'
Re-run the minimal reproduction on your broken version, then apply the fix and re-run.
Option A — Upgrade to fixed release\nUpgrade to version 0.14.0 or later.\nWhen NOT to use: This fix is not suitable if you require different URL joining semantics.\n\n
Why This Fix Works in Production
- Trigger: - If you want to append path segments to the `base_url`, be sure the base_url ends with a slash and the request path does not begin with one.
- Mechanism: The base_url handling in HTTPX did not properly manage leading slashes in relative URLs
- Why the fix works: Improves the base URL handling in HTTPX by ensuring that the base URL includes a trailing slash and strips leading slashes from relative URLs. (first fixed release: 0.14.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.8.1 in real deployments (not just unit tests).
- The base_url handling in HTTPX did not properly manage leading slashes in relative URLs
- Production symptom (often without a traceback): @florimondmanca Yeah I think that's a reasonable observation actually. It's not that our `.join(...)` behaviour is broken, but that we *shouldn't quite* be using URL joinging semantics for clients with a base URL.
Proof / Evidence
- GitHub issue: #846
- Fix PR: https://github.com/encode/httpx/pull/1130
- First fixed release: 0.14.0
- Reproduced locally: No (not executed)
- Last verified: 2026-02-09
- Confidence: 0.75
- Did this fix it?: Yes (upstream fix exists)
- Own content ratio: 0.58
Discussion
High-signal excerpts from the issue thread (symptoms, repros, edge-cases).
“I’d personally like HTTPX to be smart enough to not strip any prefix path too, _and_ allow using a leading / on subsequent requests”
“I'm just saying we shouldn't even have to _think_ about "what are the possible cases?"”
“> I don't feel the current behaviour is adequately documented True, and if we have an open issue tracking adding further docs for this behavior:…”
“To be clear, the _only_ usage I'd be expecting from base_url is… (Right now this is wrongly yielding as you noted too.) Formally: request.url =…”
Failure Signature (Search String)
- - If you want to append path segments to the `base_url`, be sure the base_url ends with a slash and the request path does not begin with one.
Copy-friendly signature
Failure Signature
-----------------
@florimondmanca Yeah I think that's a reasonable observation actually. It's not that our `.join(...)` behaviour is broken, but that we *shouldn't quite* be using URL joinging semantics for clients with a base URL.
- If you want to append path segments to the `base_url`, be sure the base_url ends with a slash and the request path does not begin with one.
Error Message
Signature-only (no traceback captured)
Error Message
-------------
@florimondmanca Yeah I think that's a reasonable observation actually. It's not that our `.join(...)` behaviour is broken, but that we *shouldn't quite* be using URL joinging semantics for clients with a base URL.
- If you want to append path segments to the `base_url`, be sure the base_url ends with a slash and the request path does not begin with one.
Minimal Reproduction
Python 3.8.1 (default, Jan 10 2020, 09:36:37)
[Clang 11.0.0 (clang-1100.0.33.16)] on darwin
>> import httpx
>> http_client = httpx.Client(base_url="https://example.com/api/v1")
>> append = http_client.get("endpoint")
>> append.url
URL('https://example.com/api/endpoint')
>> replace = http_client.get("/api/v2/new")
>> replace.url
URL('https://example.com/api/v2/new')
>> httpx.__version__
'0.11.1'
Environment
- Python: 3.8.1
- httpx: 0.11.1
What Broke
Requests with relative paths resulted in incorrect URLs, leading to 404 errors.
Why It Broke
The base_url handling in HTTPX did not properly manage leading slashes in relative URLs
Fix Options (Details)
Option A — Upgrade to fixed release Safe default (recommended)
Upgrade to version 0.14.0 or later.
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/1130
First fixed release: 0.14.0
Last verified: 2026-02-09. Validate in your environment.
When NOT to Use This Fix
- This fix is not suitable if you require different URL joining semantics.
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.
Version Compatibility Table
| Version | Status |
|---|---|
| 0.14.0 | Fixed |
Related Issues
No related fixes found.
Sources
We don’t republish the full GitHub discussion text. Use the links above for context.