SOCKS5 Proxies for aiohttp: Which Proxy Type to Use
Connect aiohttp to SOCKS5 with aiohttp-socks, then pick a type: rotating datacenter for volume, residential for strict sites, dedicated for fixed exits.
aiohttp has no SOCKS5 support of its own; install aiohttp-socks and pass a ProxyConnector. Then pick the proxy type by target: rotating datacenter for high-concurrency jobs against sites that accept hosting ranges, residential for sites that refuse them or need a country outside the US, Italy and Spain, and a dedicated datacenter proxy when the job needs the same address every time. This guide chooses between proxy types, using Node4's products as the example; Node4 publishes it and sells each one. It does not compare vendors. For that, see SOCKS5 providers compared.
Connecting aiohttp to a SOCKS5 proxy
import asyncio
from aiohttp import ClientSession
from aiohttp_socks import ProxyConnector # pip install aiohttp-socks
async def main(urls):
connector = ProxyConnector.from_url(
"socks5://USERNAME:PASSWORD@HOST:PORT", rdns=True, limit=50
)
async with ClientSession(connector=connector) as session:
async def fetch(url):
async with session.get(url) as resp:
return resp.status, await resp.text()
return await asyncio.gather(*(fetch(u) for u in urls))
print(asyncio.run(main(["https://api.ipify.org"] * 3)))Two arguments matter. rdns=True resolves hostnames at the proxy, so a targeted exit looks up the address a local visitor would get. limit caps how many connections the connector opens at once; set it to what your plan and target can take. Leave it out and aiohttp's default of 100 applies, so a gather over 10,000 URLs holds 100 connections open, which can be more than a connection-priced plan allows or a target tolerates, and the refusals that follow look like a proxy fault. The full walkthrough is in the aiohttp SOCKS5 setup guide.
One behavior to know before reading the output: on Node4's gateways an exit is chosen per connection. The three requests above run concurrently, so each opens its own connection and they will usually show different addresses. In a longer crawl, aiohttp returns finished connections to its pool and reuses them for the same host, so consecutive requests can share one connection and one exit. Pass force_close=True to the connector if every request must open a new connection, and accept the extra handshake cost.
Proxy types for aiohttp, side by side
| Product | Exits | Billing unit | Holding one exit | Use it when |
|---|---|---|---|---|
| Rotating Datacenter | Node4-owned, US/Italy/Spain | Per GB | Session id, up to 30 minutes from first assignment | Small or irregular jobs against sites that accept hosting ranges |
| Rotating Unmetered | Same pool | Concurrent connections, no data cap | Same | Heavy data through a steady connection count |
| Residential | Partner network, 170+ countries | Per GB | Session id, best effort, up to 30 min | The site refuses datacenter ranges, or you need another country |
| Dedicated datacenter | One Node4-owned address in the US, Italy or Spain | Per proxy per month, no data cap | Always the same address | A partner only accepts registered addresses, or the job needs a fixed identity |
| Shared datacenter | Node4-owned, a few accounts per address | Per proxy per month, metered | Always the same address | Light jobs and trying SOCKS5 against a target |
All five accept SOCKS5 with a username and password on paid plans. The free plan, 3 free shared proxies, 1 GB a month, no card required, is HTTP(S) only, so SOCKS5 starts on a paid plan.
Matching the connector to the plan
Rotating Unmetered. You buy a number of concurrent connections. Set limit on the connector to that number. When every connection your size allows is open, the gateway refuses new ones while the open ones keep running, so a connector limit makes extra requests wait in your client instead of failing at the gateway. See connection-based pricing for the sizes.
Rotating Datacenter. The same exits billed per gigabyte (rotating datacenter pricing), so limit is about what the target tolerates, not the bill. Measure bytes on a bounded slice of the crawl before buying a large allowance.
Residential. Put targeting in the username, for example USERNAME-country-de-session-batch7. A session is best effort for up to 30 minutes and can end sooner if the device behind the exit goes offline, so a paginated crawl should check that the exit is unchanged and restart the page sequence if it moved. Residential plan prices has the allowances.
Dedicated datacenter. One address per proxy, so give each proxy its own connector if you hold several, and spread tasks across them. Billing is per proxy with no data cap (dedicated pricing).
Sessions on the rotating gateway
A session id on the rotating datacenter gateway holds one exit for up to 30 minutes, measured from first assignment; more requests do not extend it. For a crawl that runs longer, create a new session id per batch, for example one per 500 pages, and treat a changed exit as the start of a new batch. The sticky vs rotating guide shows the username syntax.
The decision
Start with Rotating Datacenter or Rotating Unmetered and a connector limit, and choose the meter by monthly gigabytes against peak connections. Move a target to residential only when it refuses the datacenter exits or needs another country. Use a dedicated proxy when something on the other side must recognize your address. For the synchronous version of the same setup, see proxy providers for Python developers; for how rotating services bill elsewhere, see rotating proxy APIs compared.