Looks like aiohttp.ProxyConnector
doesn't support socks proxy. Is there any workaround for this? I would be grateful for any advice.
get is that requests fetches the whole body of the response at once and remembers it, but aiohttp doesn't. aiohttp lets you ignore the body, or read it in chunks, or read it after looking at the headers/status code. That's why you need to do a second await : aiohttp needs to do more I/O to get the response body.
Client session is the recommended interface for making HTTP requests. Session encapsulates a connection pool (connector instance) and supports keepalives by default.
If you need to add HTTP headers to a request, pass them in a dict to the headers parameter. await session. post(url, data='Привет, Мир! ')
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
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With