Looks like aiohttp.ProxyConnector
doesn't support socks proxy. Is there any workaround for this? I would be grateful for any advice.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Have you tried aiosocks ?
import asyncio
import aiosocks
from aiosocks.connector import SocksConnector
conn = SocksConnector(proxy=aiosocks.Socks5Addr(PROXY_ADDRESS, PROXY_PORT), proxy_auth=None, remote_resolve=True)
session = aiohttp.ClientSession(connector=conn)
async with session.get('http://python.org') as resp:
assert resp.status == 200
回答2:
aiosocks does not work with the newer version 3.+ of aiohttp. You can use aiosocksy to implement socks proxy.
To check whether aiosocksy is working you can look at the following code sample https://stackoverflow.com/a/53657536/6735546