Error handling
The Python clients call response.raise_for_status() internally, so a failed request raises httpx.HTTPStatusError. The response is attached, so you can inspect the status code and body. Successful responses return parsed JSON (a dict or list); a 204 No Content returns None.
Catching errors
import httpx
try:
pool = resources.get_pool(pool_id)
except httpx.HTTPStatusError as err:
print(f"Request failed: {err.response.status_code} {err.response.reason_phrase}")
print("Body:", err.response.text) # e.g. {"detail": "..."} on a 422
except httpx.RequestError as err:
print(f"Network error: {err}") # connection/timeout, no response
httpx.HTTPStatusError— the server returned a 4xx/5xx. Useerr.response.status_codeanderr.response.json()/.text.httpx.RequestError— the request never completed (DNS, connection, timeout). The constructortimeout(default30.0s) governs the latter.
Handling expired tokens
A 401 means the access token is missing or expired. Refresh and retry:
import httpx
def with_auth(call):
try:
return call()
except httpx.HTTPStatusError as err:
if err.response.status_code == 401:
tokens = auth.refresh_token()
resources.set_access_token(tokens["access_token"])
return call() # retry once
raise
pools = with_auth(lambda: resources.get_all_pools())
For long-running processes, call auth.auto_refresh() periodically (it refreshes when the token is near expiry) so requests rarely hit a 401.
Common statuses
| Status | Meaning | Typical fix |
|---|---|---|
400 | Bad request | Check the payload shape |
401 | Unauthenticated | Refresh or re-issue the access token |
403 | Forbidden | The user lacks permission |
404 | Not found | Verify the id / path |
422 | Validation error | Inspect err.response.json()["detail"] |