Part 04 / Topic 6 of 6
Reading errors methodically
Connectivity debugging goes fastest as a ritual, not an inspiration:
- Reproduce the failure with the smallest possible command — one curl, not the whole pipeline.
- Isolate the layer: does the name resolve (DNS)? does the port answer (TCP)? does the handshake pass (TLS)? what status comes back (HTTP)? Walk the table from lesson 3 downward.
- Compare with a known-good request — same endpoint from another machine, or another endpoint from the same machine. The difference between the working and failing case is the diagnosis.
Build a request carefully and the library handles the sharp edges — encoding, headers, the Host line:
# examples/02_build_a_request_safely_url_encoding.py
import httpx
req = httpx.Request(
"GET", "https://api.acme.example/v1/shipments",
params={"customer": "Bolt Retail & Sons", "since": "2025-04-01"},
headers={"Authorization": "Bearer <token>", "Accept": "application/json"},
)
print(req.method, req.url)
print("query string:", req.url.query.decode())
print("headers:", {k: v for k, v in req.headers.items() if k in ("authorization", "accept", "host")})
# GET https://api.acme.example/v1/shipments?customer=Bolt+Retail+%26+Sons&since=2025-04-01
# query string: customer=Bolt+Retail+%26+Sons&since=2025-04-01
# headers: {'host': 'api.acme.example', 'authorization': 'Bearer <token>', 'accept': 'application/json'}
(Note: the example builds the request without sending it — the host is fictional.)
🧪 Quick quiz
- How should the value
Bolt Retail & Sonsbe sent in a query string?
Show the answer
URL-encoded — Bolt+Retail+%26+Sons — ideally by the HTTP library, as httpx did in the example. An unencoded & would start a new parameter. (verified against the example output above)
Done here? The practice set for Part 4 — 4 exercises with solutions — is on the part page.