Is there any way to use aiohttp client with socks proxy?

后端 未结 2 1557
长发绾君心
长发绾君心 2021-02-14 17:12

Looks like aiohttp.ProxyConnector doesn\'t support socks proxy. Is there any workaround for this? I would be grateful for any advice.

相关标签:
2条回答
  • 2021-02-14 17:26

    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

    0 讨论(0)
  • 2021-02-14 17:47

    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
    
    0 讨论(0)
提交回复
热议问题