From ea2829ab433acf29c9d598a1e74cee2c0675920a Mon Sep 17 00:00:00 2001 From: Sicheng Li Date: Sun, 12 Apr 2026 17:10:27 +0800 Subject: [PATCH] fix(weixin,wecom,matrix): respect system proxy via aiohttp trust_env aiohttp.ClientSession defaults to trust_env=False, ignoring HTTP_PROXY/ HTTPS_PROXY env vars. This causes QR login and all API calls to fail for users behind a proxy (e.g. Clash in fake-ip mode), which is common in China where Weixin and WeCom are primarily used. Added trust_env=True to all aiohttp.ClientSession instantiations that connect to external hosts (weixin: 3 places, wecom: 1, matrix: 1). WhatsApp sessions are excluded as they only connect to localhost. httpx-based adapters (dingtalk, signal, wecom_callback) are unaffected as httpx defaults to trust_env=True. Co-Authored-By: Claude Sonnet 4.6 --- gateway/platforms/matrix.py | 2 +- gateway/platforms/wecom.py | 2 +- gateway/platforms/weixin.py | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/gateway/platforms/matrix.py b/gateway/platforms/matrix.py index 9f3d6358c..8855c386d 100644 --- a/gateway/platforms/matrix.py +++ b/gateway/platforms/matrix.py @@ -782,7 +782,7 @@ class MatrixAdapter(BasePlatformAdapter): # Try aiohttp first (always available), fall back to httpx try: import aiohttp as _aiohttp - async with _aiohttp.ClientSession() as http: + async with _aiohttp.ClientSession(trust_env=True) as http: async with http.get(image_url, timeout=_aiohttp.ClientTimeout(total=30)) as resp: resp.raise_for_status() data = await resp.read() diff --git a/gateway/platforms/wecom.py b/gateway/platforms/wecom.py index a0e71e01b..0249ae675 100644 --- a/gateway/platforms/wecom.py +++ b/gateway/platforms/wecom.py @@ -266,7 +266,7 @@ class WeComAdapter(BasePlatformAdapter): async def _open_connection(self) -> None: """Open and authenticate a websocket connection.""" await self._cleanup_ws() - self._session = aiohttp.ClientSession() + self._session = aiohttp.ClientSession(trust_env=True) self._ws = await self._session.ws_connect( self._ws_url, heartbeat=HEARTBEAT_INTERVAL_SECONDS * 2, diff --git a/gateway/platforms/weixin.py b/gateway/platforms/weixin.py index a83dff5a8..f8d4c5ca5 100644 --- a/gateway/platforms/weixin.py +++ b/gateway/platforms/weixin.py @@ -935,7 +935,7 @@ async def qr_login( if not AIOHTTP_AVAILABLE: raise RuntimeError("aiohttp is required for Weixin QR login") - async with aiohttp.ClientSession() as session: + async with aiohttp.ClientSession(trust_env=True) as session: try: qr_resp = await _api_get( session, @@ -1134,7 +1134,7 @@ class WeixinAdapter(BasePlatformAdapter): except Exception as exc: logger.debug("[%s] Token lock unavailable (non-fatal): %s", self.name, exc) - self._session = aiohttp.ClientSession() + self._session = aiohttp.ClientSession(trust_env=True) self._token_store.restore(self._account_id) self._poll_task = asyncio.create_task(self._poll_loop(), name="weixin-poll") self._mark_connected() @@ -1784,7 +1784,7 @@ async def send_weixin_direct( token_store.restore(account_id) context_token = token_store.get(account_id, chat_id) - async with aiohttp.ClientSession() as session: + async with aiohttp.ClientSession(trust_env=True) as session: adapter = WeixinAdapter( PlatformConfig( enabled=True,