aio-libs / aiodns

Simple DNS resolver for asyncio
https://pypi.python.org/pypi/aiodns
MIT License
532 stars 69 forks source link

Can not connect to python.org:80 [No route to host] #22

Closed lwis closed 7 years ago

lwis commented 7 years ago

Running the aiohttp client example on the homepage using aiodns 1.1.1 results in;

aiohttp.errors.ClientOSError: [Errno 65] Cannot connect to host python.org:80 ssl:False [Can not connect to python.org:80 [No route to host]]

However, running with aiodns 1.0.1 works without fault.

gwillem commented 7 years ago

You probably have an IPv6 stack but no route. Try this:

tcpconnector = aiohttp.TCPConnector(family=socket.AF_INET)
async with aiohttp.ClientSession(connector=tcpconnector) as session:
    [...]

The default was changed in aiohttp in https://github.com/KeepSafe/aiohttp/pull/561

lwis commented 7 years ago

@gwillem ah, looks like they've recognised it as an issue in any case. Thanks for the detailed response.

fannigurt commented 6 years ago
import socket

import aiohttp
import asyncio
import async_timeout

async def fetch(session, url):
    with async_timeout.timeout(10):
        async with session.get(url) as response:
            return await response.text()

async def main():
    async with aiohttp.ClientSession(connector=aiohttp.TCPConnector(family=socket.AF_INET)) as session:
        html = await fetch(session, 'http://python.org')
        print(html)

if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    loop.run_until_complete(main())

and

aiohttp.client_exceptions.ClientConnectorError: [Errno 1] Cannot connect to host python.org:443 ssl:True [Can not connect to python.org:443 [[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)]]