Python aiohttp proxy setup

Python aiohttp is one of the most common HTTP clients in scraping stacks. Point it at a PinguProxy endpoint and every request it makes exits through your proxy IP — static or rotating, over HTTP or SOCKS5.

Why use proxies with Python aiohttp

Direct requests expose your home IP and get rate-limited fast. With Python aiohttp behind PinguProxy, retries and bursts come from proxy IPs instead, so targets see distributed traffic instead of one noisy client.

What you can do

  • Keep one static IP per job so a target can whitelist or cookie you consistently.
  • Rotate per request with SOCKS5h so scraping bursts look like real distributed traffic.
  • Pool sessions with retries for long-running jobs that survive 429s and timeouts.
  • Use IPv4 or IPv6 exits depending on what the target infrastructure supports.

Setup snippets

Replace username, password, and port with the credentials from your dashboard. All examples route both HTTP and HTTPS traffic through the proxy.

Static IP (HTTP proxy)
import asyncio
import aiohttp
proxy = "http://username:password@proxy.pinguproxy.com:12933"
async def main():
async with aiohttp.ClientSession() as session:
async with session.get(
"https://pinguproxy.com/ip", proxy=proxy, timeout=aiohttp.ClientTimeout(total=10)
) as response:
print(await response.text())
asyncio.run(main())
Rotating IP (SOCKS5h)
# pip install aiohttp-socks
import asyncio
import aiohttp
from aiohttp_socks import ProxyConnector
# SOCKS5h resolves DNS on the proxy, so the exit IP is never leaked.
connector = ProxyConnector.from_url("socks5h://username:password@proxy.pinguproxy.com:12933")
async def main():
async with aiohttp.ClientSession(connector=connector) as session:
for _ in range(5):
async with session.get("https://pinguproxy.com/ip", timeout=aiohttp.ClientTimeout(total=10)) as response:
print(await response.text())
asyncio.run(main())

The port shown (12933) is the default example; your dashboard lists the exact endpoints for your proxies. SOCKS5h keeps DNS lookups on the proxy so your real DNS server never sees the target domains.

Frequently asked questions

Does Python aiohttp support SOCKS5?

Yes — modern Python aiohttp bundles the socks support needed for socks5h:// URLs; just install requests[socks] if your environment asks for it.

How do I rotate IPs per request with Python aiohttp?

Point Python aiohttp at the rotating SOCKS5h endpoint: each new connection picks a fresh exit IP, while sticky sessions keep one IP until you ask for a new one.

Can I keep the same IP for a whole scraping session?

Yes. Use the static HTTP endpoint and the same proxy URL for every request — the exit IP stays fixed until you switch proxies in the dashboard.

Other setup guides

Ready to connect Python aiohttp?

Create a proxy in the dashboard and paste your credentials into the snippets above — unlimited bandwidth on every plan.