Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClientConnectorError: Cannot connect to host python.org:80 ssl:None [Network is unreachable] #3171

Closed
rickbeeloo opened this issue Aug 2, 2018 · 6 comments
Labels
invalid This doesn't seem right

Comments

@rickbeeloo
Copy link

rickbeeloo commented Aug 2, 2018

NOTE

I know similar issues have been reported! I have tried the mentioned fixes but these did not seem to work please see steps to reproduce

Long story short

I can easily request a page (e.g. python.org) using a laptop (ubuntu). However when running the exact same code on a RedHat server I get a ClientConnectorError. Running this on a server is important for storage capacity as we retrieve terabytes of data.

Expected behaviour

Being able to send http requests

Actual behaviour

A ClientConnectorError: Cannot connect to host python.org:80 ssl:None [Network is unreachable] is raised

Steps to reproduce

import aiohttp
import asyncio
import certifi
import requests
import ssl

###################################################################
# 1. EXAMPLE FROM THE DOCS:  https://aiohttp.readthedocs.io/en/stable/
####################################################################
async def fetch(session, url):
    async with session.get(url) as response:
        return await response.text()

async def main():
    async with aiohttp.ClientSession() as session:
        await fetch(session, 'http://python.org')

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

###################################################################
# - 2. lets disable ssl check as suggested here:
# - https://github.com/aio-libs/aiohttp/issues/955
####################################################################
async def main2():
    async with aiohttp.ClientSession(connector = aiohttp.TCPConnector(verify_ssl=False)) as session:
        await fetch(session, 'http://python.org')

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

###################################################################
# - 3. Does requests work?
####################################################################
def main3():
    res = requests.get('http://python.org')
    if res.status_code != 200:
        raise Exception

main3()
###################################################################
# - 4. Maybe using the requests certificates from certif?
####################################################################

async def fetch(session, url):
    ssl_context = ssl.create_default_context(cafile=certifi.where())
    async with session.get(url, ssl = ssl_context) as response:
        return await response.text()

async def main4():
    async with aiohttp.ClientSession() as session:
        await fetch(session, 'http://python.org')


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

Running this on my laptop works fine
Running this on the server produces:

Main1

Traceback (most recent call last):
  File "test3.py", line 19, in <module>
    loop.run_until_complete(main())
  File "/data/beeloor/install_shit/miniconda/lib/python3.6/asyncio/base_events.p                                                                                                                                                             y", line 467, in run_until_complete
    return future.result()
  File "test3.py", line 16, in main
    await fetch(session, 'http://python.org')
  File "test3.py", line 11, in fetch
    async with session.get(url) as response:
  File "/data/beeloor/install_shit/miniconda/lib/python3.6/site-packages/aiohttp                                                                                                                                                             /client.py", line 843, in __aenter__
    self._resp = await self._coro
  File "/data/beeloor/install_shit/miniconda/lib/python3.6/site-packages/aiohttp                                                                                                                                                             /client.py", line 366, in _request
    timeout=timeout
  File "/data/beeloor/install_shit/miniconda/lib/python3.6/site-packages/aiohttp                                                                                                                                                             /connector.py", line 445, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/data/beeloor/install_shit/miniconda/lib/python3.6/site-packages/aiohttp                                                                                                                                                             /connector.py", line 757, in _create_connection
    req, traces, timeout)
  File "/data/beeloor/install_shit/miniconda/lib/python3.6/site-packages/aiohttp                                                                                                                                                             /connector.py", line 879, in _create_direct_connection
    raise last_exc
  File "/data/beeloor/install_shit/miniconda/lib/python3.6/site-packages/aiohttp                                                                                                                                                             /connector.py", line 862, in _create_direct_connection
    req=req, client_error=client_error)
  File "/data/beeloor/install_shit/miniconda/lib/python3.6/site-packages/aiohttp                                                                                                                                                             /connector.py", line 829, in _wrap_create_connection
    raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host python.or                                                                                                                                                             g:80 ssl:None [Network is unreachable]

Main2

 File "test3.py", line 30, in <module>
    loop.run_until_complete(main2())
  File "/data/beeloor/install_shit/miniconda/lib/python3.6/asyncio/base_events.py", line 467, in run_until_complete
    return future.result()
  File "test3.py", line 27, in main2
    await fetch(session, 'http://python.org')
  File "test3.py", line 11, in fetch
    async with session.get(url) as response:
  File "/data/beeloor/install_shit/miniconda/lib/python3.6/site-packages/aiohttp/client.py", line 843, in __aenter__
    self._resp = await self._coro
  File "/data/beeloor/install_shit/miniconda/lib/python3.6/site-packages/aiohttp/client.py", line 366, in _request
    timeout=timeout
  File "/data/beeloor/install_shit/miniconda/lib/python3.6/site-packages/aiohttp/connector.py", line 445, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/data/beeloor/install_shit/miniconda/lib/python3.6/site-packages/aiohttp/connector.py", line 757, in _create_connection
    req, traces, timeout)
  File "/data/beeloor/install_shit/miniconda/lib/python3.6/site-packages/aiohttp/connector.py", line 879, in _create_direct_connection
    raise last_exc
  File "/data/beeloor/install_shit/miniconda/lib/python3.6/site-packages/aiohttp/connector.py", line 862, in _create_direct_connection
    req=req, client_error=client_error)
  File "/data/beeloor/install_shit/miniconda/lib/python3.6/site-packages/aiohttp/connector.py", line 829, in _wrap_create_connection
    raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host python.org:80 ssl:None [Network is unreachable]

Main3
Works fine

Main4

Traceback (most recent call last):
  File "test3.py", line 56, in <module>
    loop.run_until_complete(main4())
  File "/data/beeloor/install_shit/miniconda/lib/python3.6/asyncio/base_events.py", line 467, in run_until_complete
    return future.result()
  File "test3.py", line 52, in main4
    await fetch(session, 'http://python.org')
  File "test3.py", line 47, in fetch
    async with session.get(url, ssl = ssl_context) as response:
  File "/data/beeloor/install_shit/miniconda/lib/python3.6/site-packages/aiohttp/client.py", line 843, in __aenter__
    self._resp = await self._coro
  File "/data/beeloor/install_shit/miniconda/lib/python3.6/site-packages/aiohttp/client.py", line 366, in _request
    timeout=timeout
  File "/data/beeloor/install_shit/miniconda/lib/python3.6/site-packages/aiohttp/connector.py", line 445, in connect
    proto = await self._create_connection(req, traces, timeout)
  File "/data/beeloor/install_shit/miniconda/lib/python3.6/site-packages/aiohttp/connector.py", line 757, in _create_connection
    req, traces, timeout)
  File "/data/beeloor/install_shit/miniconda/lib/python3.6/site-packages/aiohttp/connector.py", line 879, in _create_direct_connection
    raise last_exc
  File "/data/beeloor/install_shit/miniconda/lib/python3.6/site-packages/aiohttp/connector.py", line 862, in _create_direct_connection
    req=req, client_error=client_error)
  File "/data/beeloor/install_shit/miniconda/lib/python3.6/site-packages/aiohttp/connector.py", line 829, in _wrap_create_connection
    raise client_error(req.connection_key, exc) from exc
aiohttp.client_exceptions.ClientConnectorError: Cannot connect to host python.org:80 ssl:<ssl.SSLContext object at 0x7fe535866588> [Network is unreachable]

Your environment

Laptop

  • aiohttp version 3.3.2
  • python 3.6.5
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04 LTS"
NAME="Ubuntu"
VERSION="18.04 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic

Our Server

  • aiohttp version 3.3.2
  • python 3.6.2
NAME="Red Hat Enterprise Linux Server"
VERSION="7.5 (Maipo)"
ID="rhel"
ID_LIKE="fedora"
VARIANT="Server"
VARIANT_ID="server"
VERSION_ID="7.5"
PRETTY_NAME="Red Hat Enterprise Linux Server 7.5 (Maipo)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:redhat:enterprise_linux:7.5:GA:server"
HOME_URL="https://www.redhat.com/"
@webknjaz
Copy link
Member

Try aiohttp.TCPConnector(..., family=socket.AF_INET) if you don't have IPv6 configured there. Also, it's not clear how the FQDN is being resolved (into what IPs). And do you use aiodns?

@asvetlov
Copy link
Member

Issue author doesn't respond, closing

@bsolomon1124
Copy link

I can confirm that this is still sometimes present when using aiohttp.TCPConnector(..., family=socket.AF_INET) and aiodns enabled:

http://hq.81.cn/content/2019-07/25/content_9568431.htm: Cannot connect to host hq.81.cn:80 ssl:False [Name or service not known]
http://www.81.cn/gjzx/2019-07/27/content_9570659.htm: Cannot connect to host www.81.cn:80 ssl:False [Name or service not known]
http://www.81.cn/gjzx/2019-07/27/content_9570607.htm: Cannot connect to host www.81.cn:80 ssl:False [Name or service not known]
http://www.81.cn/jmywyl/2019-07/26/content_9569327.htm: Cannot connect to host www.81.cn:80 ssl:False [Name or service not known]
http://www.81.cn/gjzx/2019-07/26/content_9570050.htm: Cannot connect to host www.81.cn:80 ssl:False [Name or service not known]
http://www.81.cn/gjzx/2019-07/27/content_9570655.htm: Cannot connect to host www.81.cn:80 ssl:False [Name or service not known]
http://www.81.cn/gjzx/2019-07/26/content_9570179.htm: Cannot connect to host www.81.cn:80 ssl:False [Name or service not known]
http://www.81.cn/gjzx/2019-07/26/content_9569999.htm: Cannot connect to host www.81.cn:80 ssl:False [Name or service not known]
http://www.81.cn/gjzx/2019-07/26/content_9570020.htm: Cannot connect to host www.81.cn:80 ssl:False [Name or service not known]
http://www.81.cn/gjzx/2019-07/26/content_9569883.htm: Cannot connect to host www.81.cn:80 ssl:False [Name or service not known]
http://www.81.cn/jmywyl/2019-07/26/content_9569331.htm: Cannot connect to host www.81.cn:80 ssl:False [Name or service not known]
http://www.81.cn/jmywyl/2019-07/26/content_9569323.htm: Cannot connect to host www.81.cn:80 ssl:False [Name or service not known]
http://www.81.cn/gjzx/2019-07/26/content_9570144.htm: Cannot connect to host www.81.cn:80 ssl:False [Name or service not known]
http://www.81.cn/jmywyl/2019-07/26/content_9569330.htm: Cannot connect to host www.81.cn:80 ssl:False [Name or service not known]
http://www.81.cn/jmywyl/2019-07/27/content_9570552.htm: Cannot connect to host www.81.cn:80 ssl:False [Name or service not known]
http://www.81.cn/gjzx/2019-07/27/content_9570610.htm: Cannot connect to host www.81.cn:80 ssl:False [Name or service not known]
http://www.81.cn/theory/2019-07/26/content_9569968.htm: Cannot connect to host www.81.cn:80 ssl:False [Name or service not known]
http://www.81.cn/gjzx/2019-07/26/content_9570028.htm: Cannot connect to host www.81.cn:80 ssl:False [Name or service not known]
http://www.81.cn/gjzx/2019-07/27/content_9570603.htm: Cannot connect to host www.81.cn:80 ssl:False [Name or service not known]
http://www.81.cn/gjzx/2019-07/26/content_9569879.htm: Cannot connect to host www.81.cn:80 ssl:False [Name or service not known]
http://www.81.cn/jmywyl/2019-07/27/content_9570657.htm: Cannot connect to host www.81.cn:80 ssl:False [Name or service not known]
http://www.81.cn/gjzx/2019-07/27/content_9570637.htm: Cannot connect to host www.81.cn:80 ssl:False [Name or service not known]
http://www.81.cn/gjzx/2019-07/26/content_9570168.htm: Cannot connect to host www.81.cn:80 ssl:False [Name or service not known]
http://www.81.cn/jmywyl/2019-07/26/content_9570365.htm: Cannot connect to host www.81.cn:80 ssl:False [Name or service not known]
http://www.81.cn/gjzx/2019-07/27/content_9570647.htm: Cannot connect to host www.81.cn:80 ssl:False [Name or service not known]
http://www.81.cn/gjzx/2019-07/27/content_9570640.htm: Cannot connect to host www.81.cn:80 ssl:False [Name or service not known]
http://www.81.cn/gjzx/2019-07/26/content_9570150.htm: Cannot connect to host www.81.cn:80 ssl:False [Name or service not known]
http://www.81.cn/gjzx/2019-07/26/content_9570196.htm: Cannot connect to host www.81.cn:80 ssl:False [Name or service not known]
http://www.81.cn/gjzx/2019-07/27/content_9570671.htm: Cannot connect to host www.81.cn:80 ssl:False [Name or service not known]
http://www.81.cn/jmywyl/2019-07/27/content_9570675.htm: Cannot connect to host www.81.cn:80 ssl:False [Name or service not known]
http://www.81.cn/sydbt/2019-07/26/content_9570170.htm: Cannot connect to host www.81.cn:80 ssl:False [Name or service not known]
http://www.81.cn/gjzx/2019-07/26/content_9570035.htm: Cannot connect to host www.81.cn:80 ssl:False [Name or service not known]
http://www.81.cn/jmywyl/2019-07/26/content_9569321.htm: Cannot connect to host www.81.cn:80 ssl:False [Name or service not known]
http://www.81.cn/gjzx/2019-07/27/content_9570608.htm: Cannot connect to host www.81.cn:80 ssl:False [Name or service not known]
http://www.81.cn/gjzx/2019-07/27/content_9570596.htm: Cannot connect to host www.81.cn:80 ssl:False [Name or service not known]
http://www.81.cn/gjzx/2019-07/27/content_9570646.htm: Cannot connect to host www.81.cn:80 ssl:False [Name or service not known]
http://www.81.cn/gjzx/2019-07/27/content_9570663.htm: Cannot connect to host www.81.cn:80 ssl:False [Name or service not known]
http://www.81.cn/gjzx/2019-07/26/content_9570016.htm: Cannot connect to host www.81.cn:80 ssl:False [Name or service not known]
http://www.81.cn/gjzx/2019-07/26/content_9570171.htm: Cannot connect to host www.81.cn:80 ssl:False [Name or service not known]
http://www.81.cn/jmywyl/2019-07/27/content_9570555.htm: Cannot connect to host www.81.cn:80 ssl:False [Name or service not known]
http://www.81.cn/jmywyl/2019-07/26/content_9569852.htm: Cannot connect to host www.81.cn:80 ssl:False [Name or service not known]
http://www.81.cn/gjzx/2019-07/27/content_9570644.htm: Cannot connect to host www.81.cn:80 ssl:False [Name or service not known]
http://www.81.cn/jmywyl/2019-07/26/content_9569329.htm: Cannot connect to host www.81.cn:80 ssl:False [Name or service not known]
http://www.81.cn/jmywyl/2019-07/27/content_9570550.htm: Cannot connect to host www.81.cn:80 ssl:False [Name or service not known]
http://www.81.cn/jsdj/2019-07/26/content_9570012.htm: Cannot connect to host www.81.cn:80 ssl:False [Name or service not known]
http://www.81.cn/wjsm/2019-07/26/content_9570143.htm: Cannot connect to host www.81.cn:80 ssl:False [Name or service not known]
http://www.81.cn/jmywyl/2019-07/26/content_9569862.htm: Cannot connect to host www.81.cn:80 ssl:False [Name or service not known]
http://www.81.cn/gjzx/2019-07/26/content_9569992.htm: Cannot connect to host www.81.cn:80 ssl:False [Name or service not known]
http://www.81.cn/gjzx/2019-07/26/content_9570046.htm: Cannot connect to host www.81.cn:80 ssl:False [Name or service not known]

@webknjaz
Copy link
Member

@bsolomon1124 what if you disable aiodns?

@bsolomon1124
Copy link

bsolomon1124 commented Jul 29, 2019

@webknjaz I will try that. Would you recommend keeping use_dns_cache to its default True or setting to False? (Or maybe that's irrelevant here.)

@webknjaz
Copy link
Member

No recommendations. True should be good. But I need that for diagnostic purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid This doesn't seem right
Projects
None yet
Development

No branches or pull requests

4 participants