Skip to content

[BUG] module aiohttp has no attribute ConnectionTimeoutError - strands agents 0.1.8 #249

Open
@grhaonan

Description

@grhaonan

Checks

  • I have updated to the lastest minor and patch version of Strands
  • I have checked the documentation and this is not expected behavior
  • I have searched ./issues and there are no duplicates of my issue

Strands Version

0.1.8

Python Version

3.12.9

Operating System

ipykernel in sagemaker ai

Installation Method

pip

Steps to Reproduce

!pip install -r requirements.txt

in the requirements.txt, it has the following:
strands-agents
strands-agents-tools
strands-agents[litellm]

after installation, !pip list | grep -i "strands" shows:

strands-agents 0.1.8
strands-agents-tools 0.1.6

Expected Behavior

from strands.models.litellm import LiteLLMModel works

Actual Behavior

from strands.models.litellm import LiteLLMModel will generate the following error

`
AttributeError Traceback (most recent call last)
Cell In[14], line 1
----> 1 from strands.models.litellm import LiteLLMModel

File /opt/conda/lib/python3.12/site-packages/strands/models/litellm.py:9
6 import logging
7 from typing import Any, Optional, TypedDict, cast
----> 9 import litellm
10 from typing_extensions import Unpack, override
12 from ..types.content import ContentBlock

File /opt/conda/lib/python3.12/site-packages/litellm/init.py:329
325 disable_aiohttp_transport: bool = False # Set this to true to use httpx instead
326 force_ipv4: bool = (
327 False # when True, litellm will force ipv4 for all LLM requests. Some users have seen httpx ConnectionError when using ipv6.
328 )
--> 329 module_level_aclient = AsyncHTTPHandler(
330 timeout=request_timeout, client_alias="module level aclient"
331 )
332 module_level_client = HTTPHandler(timeout=request_timeout)
334 #### RETRIES ####

File /opt/conda/lib/python3.12/site-packages/litellm/llms/custom_httpx/http_handler.py:107, in AsyncHTTPHandler.init(self, timeout, event_hooks, concurrent_limit, client_alias, ssl_verify)
105 self.timeout = timeout
106 self.event_hooks = event_hooks
--> 107 self.client = self.create_client(
108 timeout=timeout,
109 concurrent_limit=concurrent_limit,
110 event_hooks=event_hooks,
111 ssl_verify=ssl_verify,
112 )
113 self.client_alias = client_alias

File /opt/conda/lib/python3.12/site-packages/litellm/llms/custom_httpx/http_handler.py:154, in AsyncHTTPHandler.create_client(self, timeout, concurrent_limit, event_hooks, ssl_verify)
151 timeout = _DEFAULT_TIMEOUT
152 # Create a client with a connection pool
--> 154 transport = AsyncHTTPHandler._create_async_transport(
155 ssl_context=ssl_verify if isinstance(ssl_verify, ssl.SSLContext) else None,
156 ssl_verify=ssl_verify if isinstance(ssl_verify, bool) else None,
157 )
159 return httpx.AsyncClient(
160 transport=transport,
161 event_hooks=event_hooks,
(...)
169 headers=headers,
170 )

File /opt/conda/lib/python3.12/site-packages/litellm/llms/custom_httpx/http_handler.py:499, in AsyncHTTPHandler._create_async_transport(ssl_context, ssl_verify)
495 #########################################################
496 # AIOHTTP TRANSPORT is off by default
497 #########################################################
498 if AsyncHTTPHandler._should_use_aiohttp_transport():
--> 499 return AsyncHTTPHandler._create_aiohttp_transport(
500 ssl_context=ssl_context, ssl_verify=ssl_verify
501 )
503 #########################################################
504 # HTTPX TRANSPORT is used when aiohttp is not installed
505 #########################################################
506 return AsyncHTTPHandler._create_httpx_transport()

File /opt/conda/lib/python3.12/site-packages/litellm/llms/custom_httpx/http_handler.py:547, in AsyncHTTPHandler._create_aiohttp_transport(ssl_verify, ssl_context)
536 @staticmethod
537 def _create_aiohttp_transport(
538 ssl_verify: Optional[bool] = None,
539 ssl_context: Optional[ssl.SSLContext] = None,
540 ) -> LiteLLMAiohttpTransport:
541 """
542 Creates an AiohttpTransport with RequestNotRead error handling
543
544 - If force_ipv4 is True, it will create an AiohttpTransport with local_addr set to "0.0.0.0"
545 - [Default] If force_ipv4 is False, it will create an AiohttpTransport with default settings
546 """
--> 547 from litellm.llms.custom_httpx.aiohttp_transport import LiteLLMAiohttpTransport
549 #########################################################
550 # If ssl_verify is None, set it to True
551 # TCP Connector does not allow ssl_verify to be None
552 # by default aiohttp sets ssl_verify to True
553 #########################################################
554 if ssl_verify is None:

File /opt/conda/lib/python3.12/site-packages/litellm/llms/custom_httpx/aiohttp_transport.py:18
10 from aiohttp.client import ClientResponse, ClientSession
12 from litellm._logging import verbose_logger
14 AIOHTTP_EXC_MAP: Dict = {
15 # Order matters here, most specific exception first
16 # Timeout related exceptions
17 aiohttp.ServerTimeoutError: httpx.TimeoutException,
---> 18 aiohttp.ConnectionTimeoutError: httpx.ConnectTimeout,
19 aiohttp.SocketTimeoutError: httpx.ReadTimeout,
20 # Proxy related exceptions
21 aiohttp.ClientProxyConnectionError: httpx.ProxyError,
22 # SSL related exceptions
23 aiohttp.ClientConnectorCertificateError: httpx.ProtocolError,
24 aiohttp.ClientSSLError: httpx.ProtocolError,
25 aiohttp.ServerFingerprintMismatch: httpx.ProtocolError,
26 # Network related exceptions
27 aiohttp.ClientConnectorError: httpx.ConnectError,
28 aiohttp.ClientOSError: httpx.ConnectError,
29 aiohttp.ClientPayloadError: httpx.ReadError,
30 # Connection disconnection exceptions
31 aiohttp.ServerDisconnectedError: httpx.ReadError,
32 # Response related exceptions
33 aiohttp.ClientConnectionError: httpx.NetworkError,
34 aiohttp.ClientPayloadError: httpx.ReadError,
35 aiohttp.ContentTypeError: httpx.ReadError,
36 aiohttp.TooManyRedirects: httpx.TooManyRedirects,
37 # URL related exceptions
38 aiohttp.InvalidURL: httpx.InvalidURL,
39 # Base exceptions
40 aiohttp.ClientError: httpx.RequestError,
41 }
43 # Add client_exceptions module exceptions
44 try:

File /opt/conda/lib/python3.12/site-packages/aiohttp/init.py:240, in getattr(name)
237 GunicornWebWorker = gw # type: ignore[misc]
238 return guv if name == "GunicornUVLoopWebWorker" else gw
--> 240 raise AttributeError(f"module {name} has no attribute {name}")

AttributeError: module aiohttp has no attribute ConnectionTimeoutError`

Additional Context

not sure if it is introduced since 0.1.8

Possible Solution

No response

Related Issues

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions