Skip to content

Instantly share code, notes, and snippets.

@bitnom
Created September 25, 2020 02:02
Show Gist options
  • Save bitnom/b9889c2c878f8aba40ffd12f1055240e to your computer and use it in GitHub Desktop.
Save bitnom/b9889c2c878f8aba40ffd12f1055240e to your computer and use it in GitHub Desktop.
import aiohttp
from aiohttp_socks import ProxyType, ProxyConnector, ChainProxyConnector
async def fetch(url):
connector = ProxyConnector.from_url('socks5://user:password@127.0.0.1:1080')
### or use ProxyConnector constructor
# connector = ProxyConnector(
# proxy_type=ProxyType.SOCKS5,
# host='127.0.0.1',
# port=1080,
# username='user',
# password='password',
# rdns=True
# )
### proxy chaining (since ver 0.3.3)
# connector = ChainProxyConnector.from_urls([
# 'socks5://user:password@127.0.0.1:1080',
# 'socks4://127.0.0.1:1081',
# 'http://user:password@127.0.0.1:3128',
# ])
async with aiohttp.ClientSession(connector=connector) as session:
async with session.get(url) as response:
return await response.text()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment