aiosocks
raw JSON → 0.2.6 verified Mon Apr 27 auth: no python maintenance
SOCKS proxy client for asyncio and aiohttp. Current version 0.2.6, last released in 2018. Library is in maintenance mode with very rare updates.
pip install aiosocks Common errors
error No module named 'aiosocks' ↓
cause Library not installed or Python version too old (dropped Python 3.4 in v0.2.1).
fix
pip install aiosocks
error AttributeError: module 'aiosocks' has no attribute 'connector' ↓
cause Import path incorrect; 'connector' is a submodule.
fix
from aiosocks.connector import SocksConnector
error TypeError: __init__() got an unexpected keyword argument 'request_class' ↓
cause aiohttp version mismatch; ProxyClientRequest is for aiohttp 2.x.
fix
Use aiohttp >=2.3.2 and <4.0.0.
Warnings
deprecated proxy_from_env was removed in v0.2.5. Use environment variable parsing manually. ↓
fix Manually read SOCKS_PROXY environment variable.
breaking aiohttp < 2.3.2 is no longer supported as of v0.2.5 ↓
fix Upgrade aiohttp to >=2.3.2.
gotcha SocksConnector does not support SOCKS4; only SOCKS5 and SOCKS4a. ↓
fix Use SOCKS4a or switch to another library for SOCKS4.
Imports
- SocksConnector
from aiosocks.connector import SocksConnector - ProxyClientRequest wrong
from aiosocks import ProxyClientRequestcorrectfrom aiosocks.connector import ProxyClientRequest - SOCKS5Auth wrong
from aiosocks.connector import SOCKS5Authcorrectfrom aiosocks import SOCKS5Auth
Quickstart
import asyncio
import aiohttp
from aiosocks.connector import SocksConnector, ProxyClientRequest
async def fetch():
connector = SocksConnector.from_url('socks5://user:pass@127.0.0.1:1080', remote_resolve=True)
async with aiohttp.ClientSession(connector=connector, request_class=ProxyClientRequest) as session:
async with session.get('http://example.com') as resp:
print(await resp.text())
loop = asyncio.get_event_loop()
loop.run_until_complete(fetch())