diff --git a/src/a2a/server/apps/jsonrpc/jsonrpc_app.py b/src/a2a/server/apps/jsonrpc/jsonrpc_app.py index 27839cd35..c6f78d119 100644 --- a/src/a2a/server/apps/jsonrpc/jsonrpc_app.py +++ b/src/a2a/server/apps/jsonrpc/jsonrpc_app.py @@ -64,7 +64,14 @@ from starlette.exceptions import HTTPException from starlette.requests import Request from starlette.responses import JSONResponse, Response - from starlette.status import HTTP_413_REQUEST_ENTITY_TOO_LARGE + + try: + # Starlette v0.48.0 + from starlette.status import HTTP_413_CONTENT_TOO_LARGE + except ImportError: + from starlette.status import ( # type: ignore[no-redef] + HTTP_413_REQUEST_ENTITY_TOO_LARGE as HTTP_413_CONTENT_TOO_LARGE, + ) _package_starlette_installed = True else: @@ -76,7 +83,14 @@ from starlette.exceptions import HTTPException from starlette.requests import Request from starlette.responses import JSONResponse, Response - from starlette.status import HTTP_413_REQUEST_ENTITY_TOO_LARGE + + try: + # Starlette v0.48.0 + from starlette.status import HTTP_413_CONTENT_TOO_LARGE + except ImportError: + from starlette.status import ( + HTTP_413_REQUEST_ENTITY_TOO_LARGE as HTTP_413_CONTENT_TOO_LARGE, + ) _package_starlette_installed = True except ImportError: @@ -90,7 +104,7 @@ Request = Any JSONResponse = Any Response = Any - HTTP_413_REQUEST_ENTITY_TOO_LARGE = Any + HTTP_413_CONTENT_TOO_LARGE = Any class StarletteUserProxy(A2AUser): @@ -381,7 +395,7 @@ async def _handle_requests(self, request: Request) -> Response: # noqa: PLR0911 None, A2AError(root=JSONParseError(message=str(e))) ) except HTTPException as e: - if e.status_code == HTTP_413_REQUEST_ENTITY_TOO_LARGE: + if e.status_code == HTTP_413_CONTENT_TOO_LARGE: return self._generate_error_response( request_id, A2AError(