Skip to content

Instantly share code, notes, and snippets.

@injust
Last active February 1, 2026 12:37
Show Gist options
  • Select an option

  • Save injust/6e0c1c30baa2797c0c4f354c2b5b7f07 to your computer and use it in GitHub Desktop.

Select an option

Save injust/6e0c1c30baa2797c0c4f354c2b5b7f07 to your computer and use it in GitHub Desktop.
httpx: Remove `HTTPStatusError` info suffix from `raise_for_status()`
from typing import TYPE_CHECKING, Never
import httpx
from wrapt import function_wrapper
if TYPE_CHECKING:
from collections.abc import Callable
@function_wrapper
def httpx_remove_HTTPStatusError_info_suffix( # noqa: N802
raise_for_status: Callable[[], httpx.Response], _instance: httpx.Response, args: tuple[()], kwargs: dict[str, Never]
) -> httpx.Response:
try:
return raise_for_status(*args, **kwargs)
except httpx.HTTPStatusError as e:
assert len(e.args) == 1 and isinstance(e.args[0], str), e.args
message, removed = e.args[0].rsplit("\n", 1)
assert removed.startswith("For more information check:"), removed
e.args = (message,)
raise
httpx.Response.raise_for_status = httpx_remove_HTTPStatusError_info_suffix(httpx.Response.raise_for_status)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment