From 6c2cebada2c8b21e224b171b5dae2aad541e5075 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mose=20M=C3=BCller?= Date: Wed, 21 May 2025 09:46:20 +0200 Subject: [PATCH] fix: using client without aiohttp_socks dependency does not raise When not specifying the proxy_url in `pydase.Client`, the aiohttp_socks dependency is not required. This is now handled by putting the import into the correct place, adding a descriptive log message when the import fails. --- src/pydase/client/client.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/pydase/client/client.py b/src/pydase/client/client.py index bdec294..ea5d3db 100644 --- a/src/pydase/client/client.py +++ b/src/pydase/client/client.py @@ -1,3 +1,4 @@ +from builtins import ModuleNotFoundError import asyncio import logging import sys @@ -7,7 +8,6 @@ from types import TracebackType from typing import TYPE_CHECKING, Any, TypedDict, cast import aiohttp -import aiohttp_socks.connector import socketio # type: ignore from pydase.client.proxy_class import ProxyClass @@ -150,6 +150,17 @@ class Client: def _initialize_socketio_client(self) -> None: if self._proxy_url is not None: + try: + import aiohttp_socks.connector + except ModuleNotFoundError: + raise ModuleNotFoundError( + "Missing dependency 'aiohttp_socks'. To use SOCKS5 proxy support, " + "install the optional 'socks' extra:\n\n" + ' pip install "pydase[socks]"\n\n' + "This is required when specifying a `proxy_url` for " + "`pydase.Client`." + ) + session = aiohttp.ClientSession( connector=aiohttp_socks.connector.ProxyConnector.from_url( url=self._proxy_url, loop=self._loop