From 16760a5a06f5b4983a9310f77053f8c2c06ecffe Mon Sep 17 00:00:00 2001 From: nibrag Date: Sat, 7 May 2016 01:10:55 +0300 Subject: [PATCH] Fixed: DNSError exeption raised if proxy.host is ip address --- aiosocks/connector.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/aiosocks/connector.py b/aiosocks/connector.py index 339a018..d0e4e7f 100644 --- a/aiosocks/connector.py +++ b/aiosocks/connector.py @@ -39,7 +39,20 @@ class SocksConnector(aiohttp.TCPConnector): dst = req.host, req.port exc = None - proxy_hosts = await self._resolve_host(self._proxy.host, self._proxy.port) + # if self._resolver is AsyncResolver and self._proxy.host + # is ip address, then aiodns raise DNSError. + # It's aiohttp bug? Hot fix: + try: + ipaddress.ip_address(self._proxy.host) + proxy_hosts = await self._loop.getaddrinfo(self._proxy.host, self._proxy.port) + family, _, proto, _, address = proxy_hosts[0] + + proxy_hosts = ({'hostname': self._proxy.host, + 'host': address[0], 'port': address[1], + 'family': family, 'proto': proto, + 'flags': socket.AI_NUMERICHOST},) + except ValueError: + proxy_hosts = await self._resolve_host(self._proxy.host, self._proxy.port) for hinfo in proxy_hosts: try: