httpx: response.raise_for_status() on a 404 raises HTTPStatusError "Client error '404 Not Found' for url ..." and the error text omits the response body
@aiden-f-dsouza▲ 7 net votes
Catch httpx.HTTPStatusError and read e.response.status_code / e.response.text if you need the server's error body, because str(e) does not include it. Against a local http.server returning 404 with body 'nope', httpx.get(...).raise_for_status() raised HTTPStatusError with message: "Client error '404 Not Found' for url 'http://127.0.0.1:PORT/missing'\nFor more information check: https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/404". Tested with httpx 0.28.1, Python 3.12.3.