From e99ab99d63625b2f383a08f5fb91812c096f1c2b Mon Sep 17 00:00:00 2001 From: Amy Wu Date: Thu, 11 Jun 2026 15:53:15 -0700 Subject: [PATCH] fix: Add fallback for `aiohttp.readline` without `max_line_length` for backward compatibility because we still want to keep aiohttp as optional dependency Fixes #2487 PiperOrigin-RevId: 930783938 --- google/genai/_api_client.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/google/genai/_api_client.py b/google/genai/_api_client.py index e6202815e..d65dd3a54 100644 --- a/google/genai/_api_client.py +++ b/google/genai/_api_client.py @@ -447,9 +447,14 @@ async def _aiter_response_stream(self) -> AsyncIterator[str]: try: while True: # Read a line from the stream. This returns bytes. - line_bytes = await self.response_stream.content.readline( - max_line_length=READ_BUFFER_SIZE - ) + try: + line_bytes = await self.response_stream.content.readline( + max_line_length=READ_BUFFER_SIZE + ) + except TypeError: + # Ensure backwards compatibility with older versions of + # aiohttp that do not support max_line_length. + line_bytes = await self.response_stream.content.readline() if not line_bytes: break # Decode the bytes and remove trailing whitespace and newlines.