python 3.5 asyncio und aiohttp Errno 101 Netzwerk ist nicht erreichbar

Ich benutze Python 3.5 auf Ubuntu 16.

Ich versuche, mit aiohttp einen einfachen Client zu schreiben.

Hier ist der Code, den ich habe. Ich habe es von @ genommHie. Es ist das erste Codebeispiel mit deaktivierter SSL-Prüfung:

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(loop):
    conn = aiohttp.TCPConnector(verify_ssl=False)
    async with aiohttp.ClientSession(loop=loop, connector=conn) as session:
        html = await fetch(session, 'http://www.google.com')
        print(html)

loop = asyncio.get_event_loop()
loop.run_until_complete(main(loop))

loop = asyncio.get_event_loop()
loop.run_until_complete(main(loop))
<p>For some sites, this code works. For others, including <code>http://python.org</code> or <code>http://google.com</code> it does not work. Instead, the code generates this error:</p><pre><code>aiohttp.errors.ClientOSError: [Errno 101] Cannot connect to host google.com:80 ssl:False [Can not connect to google.com:80 [Network is unreachable]] </code></pre><p>I tried a simple <code>requests</code> script, something like this:</p><pre><code>import requests rsp = requests.get('http://google.com') print(rsp.text) </code></pre><p>This works, I am able to reach google. Both curl and wget also reach google.</p><p>Doing some research, I came across a different problem. That problem is similar to my own. I found it <a href="https://stackoverflow.com/questions/29827642/asynchronous-aiohttp-requests-fails-but-synchronous-requests-succeed" rel="nofollow">here</a>. I tried the solution offered here, but it still does not work.</p><p>This issue does not occur for all sites. I came across both http and https sites that worked and did not work.</p><p>Any suggestions on why this happens and how can I fix this?</p><p>Thank you!</p><p>Notes:</p><p>Other things I tried.</p>Adding my own DNS resolver, also using aiohttp.Using the https version of the sites, getting the same error.Going to a slightly different url, for example <code>https://www.google.com/?#q=python</code>

Antworten auf die Frage(2)

Ihre Antwort auf die Frage