From 3b930f67366dba83316177d8c2b4111a7efddc69 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Sat, 31 May 2025 13:02:07 -0700 Subject: [PATCH] fix: aiohttp handle transfer encoding errors gracefully --- litellm/llms/custom_httpx/aiohttp_transport.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/litellm/llms/custom_httpx/aiohttp_transport.py b/litellm/llms/custom_httpx/aiohttp_transport.py index ca408651e6..81dab9f674 100644 --- a/litellm/llms/custom_httpx/aiohttp_transport.py +++ b/litellm/llms/custom_httpx/aiohttp_transport.py @@ -5,6 +5,7 @@ from typing import Callable, Dict, Union import aiohttp import aiohttp.client_exceptions +import aiohttp.http_exceptions import httpx from aiohttp.client import ClientResponse, ClientSession @@ -81,13 +82,20 @@ class AiohttpResponseStream(httpx.AsyncByteStream): self.CHUNK_SIZE ): yield chunk - except aiohttp.ClientPayloadError as e: + except ( + aiohttp.ClientPayloadError, + aiohttp.client_exceptions.ClientPayloadError, + ) as e: # Handle incomplete transfers more gracefully # Log the error but don't re-raise if we've already yielded some data verbose_logger.debug(f"Transfer incomplete, but continuing: {e}") # If the error is due to incomplete transfer encoding, we can still # return what we've received so far, similar to how httpx handles it return + except aiohttp.http_exceptions.TransferEncodingError as e: + # Handle transfer encoding errors gracefully + verbose_logger.debug(f"Transfer encoding error, but continuing: {e}") + return except Exception: # For other exceptions, use the normal mapping with map_aiohttp_exceptions(): @@ -203,7 +211,6 @@ class LiteLLMAiohttpTransport(AiohttpTransport): data=data, allow_redirects=False, auto_decompress=False, - compress=False, timeout=ClientTimeout( sock_connect=timeout.get("connect"), sock_read=timeout.get("read"),