Aioweb migration #3

Merged
TPV merged 2 commits from aioweb-migration into main 2026-07-19 16:29:00 +00:00
Showing only changes of commit 638d8fb359 - Show all commits
+12 -3
View File
@@ -13,12 +13,16 @@ from aioweb import Response
from aioweb_tls import CurlCffi, TLSSession
from fake_useragent import UserAgent
from monitor_utils.constants import CLIENT_IDENTIFIERS, RETRY_LIMIT
from monitor_utils.constants import CLIENT_IDENTIFIERS, RETRY_LIMIT, TIMEOUT_SECONDS
UA = UserAgent()
def get_default_session(proxies: AioProxies, headers: dict | None = None) -> TLSSession:
def get_default_session(
proxies: AioProxies,
headers: dict | None = None,
timeout: int = TIMEOUT_SECONDS,
) -> TLSSession:
"""Return a TLSSession impersonating a random client fingerprint.
Fingerprint rotation lives here so every monitor rotates the same way; the
@@ -36,6 +40,9 @@ def get_default_session(proxies: AioProxies, headers: dict | None = None) -> TLS
monitor-wide static headers; per-request headers still go through
send_request. The curl_cffi impersonation already supplies a
matching User-Agent, so one is not defaulted here.
timeout: Total request timeout in seconds, defaulting to TIMEOUT_SECONDS.
aioweb's own default is only 10s, so this restores the wider budget
the old sessions used and slow retailers depend on.
Returns:
A TLSSession over a curl_cffi backend with a random impersonation, with
@@ -45,7 +52,9 @@ def get_default_session(proxies: AioProxies, headers: dict | None = None) -> TLS
headers = headers or {}
headers.setdefault("User-Agent", UA.chrome)
impersonate = random.choice(CLIENT_IDENTIFIERS)
session = TLSSession(backend=CurlCffi(impersonate=impersonate), headers=headers)
session = TLSSession(
backend=CurlCffi(impersonate=impersonate), headers=headers, timeout=timeout
)
session.proxy_pool = proxies
return session