From 3515af6fd8c64cedc9b0be7aad0091bb499b89bb Mon Sep 17 00:00:00 2001 From: TPV Date: Fri, 17 Jul 2026 20:37:16 -0700 Subject: [PATCH] added proxies to default session --- src/monitor_utils/sessions.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/monitor_utils/sessions.py b/src/monitor_utils/sessions.py index f7dc2e3..b726fad 100644 --- a/src/monitor_utils/sessions.py +++ b/src/monitor_utils/sessions.py @@ -22,13 +22,19 @@ def get_default_session(proxies: AioProxies) -> TLSSession: caller owns the session lifetime via ``async with``. Args: - proxies: used for rotating proxies inside of send_request + proxies: Pool attached to the session as proxy_pool, which send_request + rotates through per request. Required so a session can never send + un-proxied. Returns: - A TLSSession over a curl_cffi backend with a random impersonation. + A TLSSession over a curl_cffi backend with a random impersonation, with + the proxy pool attached as proxy_pool. """ - return TLSSession(backend=CurlCffi(impersonate=random.choice(CLIENT_IDENTIFIERS))) + impersonate = random.choice(CLIENT_IDENTIFIERS) + session = TLSSession(backend=CurlCffi(impersonate=impersonate)) + session.proxy_pool = proxies + return session async def send_request( @@ -36,7 +42,6 @@ async def send_request( url: str, method: str, *, - proxies: AioProxies, params: dict | None = None, json_data: dict | None = None, data: dict | None = None, @@ -56,8 +61,6 @@ async def send_request( session: The TLSSession to send through. url: Request URL. method: HTTP method. - proxies: Proxy pool (required); the next proxy is drawn per call and - applied to both http and https. params: Query parameters. json_data: JSON body. A dict here is sent as a JSON body. data: Alternative body. Note aioweb routes any dict or list to a JSON @@ -74,7 +77,7 @@ async def send_request( AiowebError: On a non-2xx response or after all retries fail. """ - proxy_url = proxies.next().url() + proxy_url = session.proxy_pool.next().url() proxy = {"http": proxy_url, "https": proxy_url} body = json_data if json_data is not None else data