Proxy in aiohttp with authentication

In aiohttp an HTTP proxy is passed in the proxy parameter right in the request. SOCKS5 needs a separate connector. Both variants are below.

HTTPHTTPSSOCKS5Login and passwordRotation and sticky
aiohttp · proxy
http://LOGIN:PASSWORD@HOST:PORT
socks5://LOGIN:PASSWORD@HOST:PORT
15
✓ IP: Germany, residentialRun

Why use a proxy in aiohttp

aiohttp is an async HTTP client and server for Python on asyncio. An HTTP proxy is set with the proxy argument of session.get or ClientSession; login and password can go in the URL. aiohttp can't do SOCKS by itself; the aiohttp-socks package covers it.

What to pick

HTTP is handier in aiohttp: no extra packages and the login comes from the URL. Add SOCKS5 via aiohttp-socks if the task needs it. For bulk async collection choose rotation; for sessions with an account login, sticky.

Residential

from $0.6 / GB

Home ISP addresses. The main choice for accounts and protected sites.

VIP

$2 / GB

Hand-picked clean IPs, faster and more stable than regular residential.

Mobile

$4 / GB

Carrier IPs, for platforms that check addresses strictly.

Step-by-step setup

Button names are given exactly as they appear in aiohttp.

  1. Install aiohttp

    Run pip install aiohttp. For SOCKS5 add pip install aiohttp-socks.

  2. Build the proxy string

    Export login:pass@ip:port in @SousProxyBot and prepend http://. Encode a password with special characters.

  3. Pass proxy to the request

    Put the whole string in session.get(url, proxy=PROXY). You can also set it once for the whole session: ClientSession(proxy=PROXY).

  4. Run it

    Save the example as ip.py and run python ip.py.

  5. Check the IP

    The console shows JSON with the proxy IP. Check the address's country on /en/tools/ip-type/.

Code example

Put in your own HOST, PORT, LOGIN and PASSWORD from the bot or the dashboard.

python
import asyncio
import aiohttp

PROXY = "http://LOGIN:PASSWORD@HOST:PORT"


async def main():
    timeout = aiohttp.ClientTimeout(total=15)
    async with aiohttp.ClientSession(timeout=timeout) as session:
        async with session.get("https://api.ipify.org?format=json",
                               proxy=PROXY) as resp:
            print(await resp.json())


asyncio.run(main())

Tested by running it

We ran this example ourselves: Python 3.13.18 · aiohttp 3.14.5. Real output below, IP hidden.

Terminal · ip.py
$ python ip.py
{'ip': 'proxy IP'}

And this is the response when the password is wrong:

$ python ip.py
…
    raise ClientHttpProxyError(
    ...<5 lines>...
    )
aiohttp.client_exceptions.ClientHttpProxyError: 407, message='Proxy Authentication Required', url='http://LOGIN:wrong-pass@HOST:PORT'

Common errors

The issues people most often bring to support.

!

DeprecationWarning about proxy_authRecent aiohttp versions deprecate proxy_auth. Put login and password in the proxy URL or pass a Proxy-Authorization header via proxy_headers.

!

Error with socks5:// in the proxy parameteraiohttp's proxy accepts only HTTP proxies. For SOCKS5 create the session with connector=ProxyConnector.from_url("socks5://...") from aiohttp-socks.

!

ClientHttpProxyError: 407The login or password was rejected. Check the string and encode special characters in the password.

!

ServerDisconnectedError on some requestsToo many concurrent connections or a slow IP. Limit concurrency with asyncio.Semaphore and test the proxy on /en/tools/proxy-checker/.

Need a proxy for aiohttp?

Residential, VIP and mobile IPs. HTTP and SOCKS5, pay per GB, 1 GB free to try.

FAQ

How do I connect SOCKS5?

from aiohttp_socks import ProxyConnector; connector = ProxyConnector.from_url("socks5://LOGIN:PASSWORD@HOST:PORT"); then aiohttp.ClientSession(connector=connector). No proxy parameter is needed in the request then.

Can I set the proxy for the whole session?

Yes, ClientSession accepts a default proxy. The proxy argument in an individual request overrides it.

How do I get a new IP per request?

Export the proxy in rotation mode. The string in the code stays the same; the address changes on the proxy side.