async def _wrap_create_connection(self, protocol_factory, host, port, **kwargs): proxies = [] for info in self._proxy_infos: proxy = Proxy.create(proxy_type=info.proxy_type, host=info.host, port=info.port, username=info.username, password=info.password, rdns=info.rdns, loop=self._loop) proxies.append(proxy) proxy = ProxyChain(proxies) connect_timeout = None timeout = kwargs.get('timeout') if timeout is not None: connect_timeout = getattr(timeout, 'sock_connect', None) sock = await proxy.connect(host, port, timeout=connect_timeout) return await super()._wrap_create_connection(protocol_factory, None, None, sock=sock, **kwargs)
async def main(): proxy = ProxyChain([ Proxy.from_url(SOCKS5_IPV4_URL), Proxy.from_url(SOCKS4_URL), Proxy.from_url(HTTP_PROXY_URL), ]) # noinspection PyTypeChecker status_code = await make_request(proxy=proxy, url=TEST_URL) assert status_code == 200