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

╄→гoц情女王★ 提交于 2019-12-12 08:04:40

问题


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



来源:https://stackoverflow.com/questions/36960800/is-there-any-way-to-use-aiohttp-client-with-socks-proxy

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!