Skip to content Skip to sidebar Skip to footer

How To Use SOCKS Proxies To Make Requests With Aiohttp?

I am trying to use aiohttp to make asynchronous HTTP requests over multiple SOCKS proxies. Basically, I am creating a pool of Tor clients with different IP addresses, and want to b

Solution 1:

I tried using aiosocks for my project to get the same error as yours only to later discover that aiosocks has been abandoned.

You can use aiosocksy instead.

import asyncio
import aiohttp
from aiosocksy import Socks5Auth
from aiosocksy.connector import ProxyConnector, ProxyClientRequest


async def fetch(url):
    connector = ProxyConnector()
    socks = 'socks5://127.0.0.1:9050'
    async with aiohttp.ClientSession(connector=connector, request_class=ProxyClientRequest) as session:
        async with session.get(url, proxy=socks) as response:
            print(await response.text())


loop = asyncio.get_event_loop()
loop.run_until_complete(fetch('http://httpbin.org/ip'))

Post a Comment for "How To Use SOCKS Proxies To Make Requests With Aiohttp?"