One aiohttp Request Through an HTTP Proxy
Make an unauthenticated HTTP-proxy request with aiohttp, inspect its status and finish within an explicit async lifecycle.
For one asynchronous request through an unauthenticated HTTP proxy, keep the route on session.get(). Add aiohttp to the project if needed:
uv add aiohttpReplace the documentation address below with your HTTP listener or a candidate from the HTTP proxy list. It must permit CONNECT to the HTTPS destination; a SOCKS-only endpoint needs a suitable connector instead of this proxy argument.
import asyncio
import aiohttp
async def main():
timeout = aiohttp.ClientTimeout(total=15, connect=5)
async with aiohttp.ClientSession(
timeout=timeout,
trust_env=False,
) as session:
async with session.get(
"https://example.com/",
proxy="http://203.0.113.10:8080",
) as response:
print(response.status)
print((await response.text())[:200])
asyncio.run(main())
The request prints its HTTP status and the first 200 characters of the response text. A 403 or 429 remains an inspectable response here; call response.raise_for_status() if your application should turn unsuccessful statuses into exceptions. The async context managers close the session and response when their blocks finish, including on an exception.
The 15-second total budget covers the request operation. The 5-second connect budget includes waiting for an available pooled connection, so a busy pool can consume it before a new socket opens. This distinction matters when adapting the single call into concurrent checks.
trust_env=False keeps the shown route explicit. aiohttp does not discover proxy environment variables by default; exporting one in another terminal will not configure this call. Choose trust_env=True only when the process's inherited environment is the intended routing policy.