From f82a08b50017d148b12bf8157ba313d32b6e0fbe Mon Sep 17 00:00:00 2001 From: Adeev Mardia <71126451+adeev-mardia@users.noreply.github.com> Date: Tue, 28 Jul 2026 15:28:09 +0530 Subject: [PATCH 1/2] fix: handle non-IANA HTTP status codes in generated clients Add try/except in _build_response so that non-IANA status codes (e.g. 520 Cloudflare, 561 AWS WAF, 499 nginx) fall back to raw int instead of raising ValueError from HTTPStatus(). Fixes #1442 --- openapi_python_client/templates/endpoint_module.py.jinja | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/openapi_python_client/templates/endpoint_module.py.jinja b/openapi_python_client/templates/endpoint_module.py.jinja index 63e617778..5c5cd6574 100644 --- a/openapi_python_client/templates/endpoint_module.py.jinja +++ b/openapi_python_client/templates/endpoint_module.py.jinja @@ -32,7 +32,7 @@ def _get_kwargs( {% if endpoint.path_parameters %} "url": "{{ endpoint.path }}".format( {%- for parameter in endpoint.path_parameters -%} - {{parameter.python_name}}=quote(str({{parameter.python_name}}), safe=""), + {{parameter.python_name}}=\quote(str({{parameter.python_name}}), safe=\"\"), {%- endfor -%} ), {% else %} @@ -99,8 +99,12 @@ def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Res def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[{{ return_string }}]: + try: + status_code = HTTPStatus(response.status_code) + except ValueError: + status_code = response.status_code return Response( - status_code=HTTPStatus(response.status_code), + status_code=status_code, content=response.content, headers=response.headers, parsed=_parse_response(client=client, response=response), From 0f8c7f86c768fd47173e6539518df71754d40a81 Mon Sep 17 00:00:00 2001 From: Adeev Mardia <71126451+adeev-mardia@users.noreply.github.com> Date: Tue, 28 Jul 2026 15:28:10 +0530 Subject: [PATCH 2/2] fix: handle non-IANA HTTP status codes in generated clients Widen Response.status_code type from HTTPStatus to HTTPStatus | int so generated clients don't crash with ValueError on vendor-specific status codes like 520 (Cloudflare), 561 (AWS WAF), or 499 (nginx). Fixes #1442 --- openapi_python_client/templates/types.py.jinja | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openapi_python_client/templates/types.py.jinja b/openapi_python_client/templates/types.py.jinja index f74db0ad7..a36465f5a 100644 --- a/openapi_python_client/templates/types.py.jinja +++ b/openapi_python_client/templates/types.py.jinja @@ -44,7 +44,7 @@ T = TypeVar("T") class Response(Generic[T]): """ A response from an endpoint """ - status_code: HTTPStatus + status_code: HTTPStatus | int content: bytes headers: MutableMapping[str, str] parsed: T | None