Aioweb migration #1

Merged
TPV merged 5 commits from aioweb-migration into main 2026-07-19 01:26:35 +00:00
Showing only changes of commit 3515af6fd8 - Show all commits
+10 -7
View File
@@ -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