-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't set proxy per request #31
Comments
To send requests through a proxy, you first need to establish a connection with it. The connection to the proxy is performed by
In this case (proxy per request)
It did it as described above in relation to In any case, we can not modify aiohttp request methods (session.get(...) etc.) (and there is absolutely no need for this). Why not use a function like this: async def fetch_via_proxy(proxy_url, target_url):
connector = ProxyConnector.from_url(proxy_url)
async with aiohttp.ClientSession(connector=connector) as session:
async with session.get(target_url) as res:
return await res.text() This is what you need if you use different proxies for each request. |
aiohttp creates new connections only when there are not any available in connections pool, even for proxies (they include proxy in
Proxy per request could be easily implemented by overriding |
And even If you send request to different origins or connect to different proxies? (or what do you mean by "proxy per request"?)
Yes, if you have a connection to the single server (in our case, a proxy server). But you want to change the proxy for every request, don't you?
This will require rewriting a lot of the TCPConnector code (via copy-pasting, how it was implemented aiosocksy) It all makes no sense. aiohttp session is just a connection to the proxy server, and for different proxies you must open a new session. |
I didn't mean unique proxy per request, but allow proxies to be changed arbitrarly for same session. Yes aiohttp will create new connection for different origins, the Anyway, I will fork this project or reimplement socks5 client myself. |
Good luck |
I implemented that and published now at https://github.com/HMaker/aiohttp-socks5
Not true, check implementation above. |
You're a king bro. |
aiohttp allows one to set proxies per request, this is not possible with
aiohttp_socks
because it overrides session's connector which takes static proxy, so same proxy will be used for all requests of that session.From the readme I understood this feature existed on aiosocksy but was removed to make codebase more maintainable, but it kills use cases which requires proxy rotation or proxy bypass.
If maintanability is a possible issue why not keep both versions? one subclass of
TCPConnector
for static proxies and another one for dynamic proxies. When the dynamic version break people can still use the static one. Also to avoid breakage this package can pin aiohttp version onrequirements.txt
.The text was updated successfully, but these errors were encountered: