当前位置: 首页>>代码示例>>Python>>正文


Python errno.ENETUNREACH属性代码示例

本文整理汇总了Python中errno.ENETUNREACH属性的典型用法代码示例。如果您正苦于以下问题:Python errno.ENETUNREACH属性的具体用法?Python errno.ENETUNREACH怎么用?Python errno.ENETUNREACH使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在errno的用法示例。


在下文中一共展示了errno.ENETUNREACH属性的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: connect

# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENETUNREACH [as 别名]
def connect(self, address):
        """
        Try to make an actual connection.
        :return: True if connected
        """
        sock = self._connectors[address]
        err = sock.connect()

        self.poller.register(sock)
        self._sock_by_fd[sock.fileno()] = sock
        self._socks_waiting_to_connect.add(sock)

        if err in (0, errno.EISCONN):
            self.handle_connect(sock)
            return True
        elif err in (errno.ECONNREFUSED, errno.ENETUNREACH):
            self.handle_conn_refused(sock)
        elif err not in (errno.EINPROGRESS, errno.EWOULDBLOCK):
            raise socket.error(err, errno.errorcode[err])

        return False

    ########################################################## 
开发者ID:blackye,项目名称:luscan-devel,代码行数:25,代码来源:link.py

示例2: test_send_command_othererror_connecting

# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENETUNREACH [as 别名]
def test_send_command_othererror_connecting(self):
        collectd = Mock()

        self.socket.connect.side_effect = IOError(errno.ENETUNREACH)

        s = HAProxySocket(collectd, "/var/run/sock.sock")

        with self.assertRaises(IOError):
            s.send_command("a command") 
开发者ID:wglass,项目名称:collectd-haproxy,代码行数:11,代码来源:test_connection.py

示例3: test_create_connection

# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENETUNREACH [as 别名]
def test_create_connection(self):
        # Issue #9792: errors raised by create_connection() should have
        # a proper errno attribute.
        port = test_support.find_unused_port()
        with self.assertRaises(socket.error) as cm:
            socket.create_connection((HOST, port))

        # Issue #16257: create_connection() calls getaddrinfo() against
        # 'localhost'.  This may result in an IPV6 addr being returned
        # as well as an IPV4 one:
        #   >>> socket.getaddrinfo('localhost', port, 0, SOCK_STREAM)
        #   >>> [(2,  2, 0, '', ('127.0.0.1', 41230)),
        #        (26, 2, 0, '', ('::1', 41230, 0, 0))]
        #
        # create_connection() enumerates through all the addresses returned
        # and if it doesn't successfully bind to any of them, it propagates
        # the last exception it encountered.
        #
        # On Solaris, ENETUNREACH is returned in this circumstance instead
        # of ECONNREFUSED.  So, if that errno exists, add it to our list of
        # expected errnos.
        expected_errnos = [ errno.ECONNREFUSED, ]
        if hasattr(errno, 'ENETUNREACH'):
            expected_errnos.append(errno.ENETUNREACH)
        if hasattr(errno, 'EADDRNOTAVAIL'):
            # bpo-31910: socket.create_connection() fails randomly
            # with EADDRNOTAVAIL on Travis CI
            expected_errnos.append(errno.EADDRNOTAVAIL)

        self.assertIn(cm.exception.errno, expected_errnos) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:32,代码来源:test_socket.py

示例4: test_create_connection

# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENETUNREACH [as 别名]
def test_create_connection(self):
        # Issue #9792: errors raised by create_connection() should have
        # a proper errno attribute.
        port = test_support.find_unused_port()
        with self.assertRaises(socket.error) as cm:
            socket.create_connection((HOST, port))

        # Issue #16257: create_connection() calls getaddrinfo() against
        # 'localhost'.  This may result in an IPV6 addr being returned
        # as well as an IPV4 one:
        #   >>> socket.getaddrinfo('localhost', port, 0, SOCK_STREAM)
        #   >>> [(2,  2, 0, '', ('127.0.0.1', 41230)),
        #        (26, 2, 0, '', ('::1', 41230, 0, 0))]
        #
        # create_connection() enumerates through all the addresses returned
        # and if it doesn't successfully bind to any of them, it propagates
        # the last exception it encountered.
        #
        # On Solaris, ENETUNREACH is returned in this circumstance instead
        # of ECONNREFUSED.  So, if that errno exists, add it to our list of
        # expected errnos.
        expected_errnos = [ errno.ECONNREFUSED, ]
        if hasattr(errno, 'ENETUNREACH'):
            expected_errnos.append(errno.ENETUNREACH)

        self.assertIn(cm.exception.errno, expected_errnos) 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:28,代码来源:test_socket.py

示例5: test_errno

# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENETUNREACH [as 别名]
def test_errno(self):
        """
        L{error.getConnectError} converts based on errno for C{socket.error}.
        """
        self.assertErrnoException(errno.ENETUNREACH, error.NoRouteError)
        self.assertErrnoException(errno.ECONNREFUSED, error.ConnectionRefusedError)
        self.assertErrnoException(errno.ETIMEDOUT, error.TCPTimedOutError)
        if platformType == "win32":
            self.assertErrnoException(errno.WSAECONNREFUSED, error.ConnectionRefusedError)
            self.assertErrnoException(errno.WSAENETUNREACH, error.NoRouteError) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:12,代码来源:test_error.py

示例6: is_network_error

# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENETUNREACH [as 别名]
def is_network_error(exception) -> bool:
    """
    :param exception: an exception error instance
    :return: True if exception detected as a network error, False otherwise
    """
    network_errors = [errno.ECONNABORTED, errno.ECONNREFUSED, errno.ENETRESET, errno.ECONNRESET,
                      errno.ENETUNREACH, errno.ENETDOWN]

    if isinstance(exception, HTTPError) or isinstance(exception, RequestException) or \
            hasattr(exception, 'errno') and exception.errno in network_errors:
        return True

    return False 
开发者ID:gnosis,项目名称:django-eth-events,代码行数:15,代码来源:utils.py

示例7: test_create_connection

# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENETUNREACH [as 别名]
def test_create_connection(self):
        # Issue #9792: errors raised by create_connection() should have
        # a proper errno attribute.
        port = support.find_unused_port()
        with self.assertRaises(OSError) as cm:
            socket.create_connection((HOST, port))

        # Issue #16257: create_connection() calls getaddrinfo() against
        # 'localhost'.  This may result in an IPV6 addr being returned
        # as well as an IPV4 one:
        #   >>> socket.getaddrinfo('localhost', port, 0, SOCK_STREAM)
        #   >>> [(2,  2, 0, '', ('127.0.0.1', 41230)),
        #        (26, 2, 0, '', ('::1', 41230, 0, 0))]
        #
        # create_connection() enumerates through all the addresses returned
        # and if it doesn't successfully bind to any of them, it propagates
        # the last exception it encountered.
        #
        # On Solaris, ENETUNREACH is returned in this circumstance instead
        # of ECONNREFUSED.  So, if that errno exists, add it to our list of
        # expected errnos.
        expected_errnos = [ errno.ECONNREFUSED, ]
        if hasattr(errno, 'ENETUNREACH'):
            expected_errnos.append(errno.ENETUNREACH)

        self.assertIn(cm.exception.errno, expected_errnos) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:28,代码来源:test_socket.py

示例8: get_node_ip_address

# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENETUNREACH [as 别名]
def get_node_ip_address(address="8.8.8.8:53"):
    """Determine the IP address of the local node.

    Args:
        address (str): The IP address and port of any known live service on the
            network you care about.

    Returns:
        The IP address of the current node.
    """
    if ray.worker._global_node is not None:
        return ray.worker._global_node.node_ip_address

    ip_address, port = address.split(":")
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    try:
        # This command will raise an exception if there is no internet
        # connection.
        s.connect((ip_address, int(port)))
        node_ip_address = s.getsockname()[0]
    except OSError as e:
        node_ip_address = "127.0.0.1"
        # [Errno 101] Network is unreachable
        if e.errno == errno.ENETUNREACH:
            try:
                # try get node ip address from host name
                host_name = socket.getfqdn(socket.gethostname())
                node_ip_address = socket.gethostbyname(host_name)
            except Exception:
                pass
    finally:
        s.close()

    return node_ip_address 
开发者ID:ray-project,项目名称:ray,代码行数:36,代码来源:services.py

示例9: find_local_ip

# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENETUNREACH [as 别名]
def find_local_ip(host=None):
    # see here: http://stackoverflow.com/questions/166506/
    try:
        if host is None:
            host = socket.gethostname()

        if 'local' not in host:
            host += '.local'

        try:
            ips = [ip for ip in socket.gethostbyname_ex(host)[2]
                   if not ip.startswith('127.')]
            if len(ips):
                return ips[0]
        except socket.gaierror:
            logger.debug('socket gaierror with hostname {}'.format(host))
            pass

        # If the above method fails (depending on the system)
        # Tries to ping google DNS instead (need a internet connexion)
        try:
            with closing(socket.socket()) as s:
                s.settimeout(1)
                s.connect(('8.8.8.8', 53))
                return s.getsockname()[0]
        except socket.timeout:
            logger.debug('socket timeout')
            pass

    except IOError as e:
        # network unreachable
        # error no 10065 = WSAESERVERUNREACH Windows Network unreachable
        if e.errno == errno.ENETUNREACH or e.errno == 10065:
            logger.debug('network unreachable')
            pass
        else:
            raise
    return '127.0.0.1' 
开发者ID:poppy-project,项目名称:pypot,代码行数:40,代码来源:snap.py

示例10: _conn_request

# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENETUNREACH [as 别名]
def _conn_request(self, conn, request_uri, method, body, headers):
        i = 0
        seen_bad_status_line = False
        while i < RETRIES:
            i += 1
            try:
                if hasattr(conn, 'sock') and conn.sock is None:
                    conn.connect()
                conn.request(method, request_uri, body, headers)
            except socket.timeout:
                raise
            except socket.gaierror:
                conn.close()
                raise ServerNotFoundError("Unable to find the server at %s" % conn.host)
            except ssl_SSLError:
                conn.close()
                raise
            except socket.error, e:
                err = 0
                if hasattr(e, 'args'):
                    err = getattr(e, 'args')[0]
                else:
                    err = e.errno
                if err in (errno.ENETUNREACH, errno.EADDRNOTAVAIL) and i < RETRIES:
                    continue  # retry on potentially transient socket errors
                raise
            except httplib.HTTPException:
                # Just because the server closed the connection doesn't apparently mean
                # that the server didn't send a response.
                if hasattr(conn, 'sock') and conn.sock is None:
                    if i < RETRIES-1:
                        conn.close()
                        conn.connect()
                        continue
                    else:
                        conn.close()
                        raise
                if i < RETRIES-1:
                    conn.close()
                    conn.connect()
                    continue 
开发者ID:splunk,项目名称:SA-ctf_scoreboard,代码行数:43,代码来源:__init__.py

示例11: get_ip_address

# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENETUNREACH [as 别名]
def get_ip_address():
  """Simple utility to get host IP address."""
  try:
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.connect(("8.8.8.8", 80))
    ip_address = s.getsockname()[0]
  except socket_error as sockerr:
    if sockerr.errno != errno.ENETUNREACH:
      raise sockerr
    ip_address = socket.gethostbyname(socket.getfqdn())
  finally:
    s.close()

  return ip_address 
开发者ID:yahoo,项目名称:TensorFlowOnSpark,代码行数:16,代码来源:util.py

示例12: _conn_request

# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENETUNREACH [as 别名]
def _conn_request(self, conn, request_uri, method, body, headers):
        i = 0
        seen_bad_status_line = False
        while i < RETRIES:
            i += 1
            try:
                if hasattr(conn, 'sock') and conn.sock is None:
                    conn.connect()
                conn.request(method, request_uri, body, headers)
            except socket.timeout:
                raise
            except socket.gaierror:
                conn.close()
                raise ServerNotFoundError("Unable to find the server at %s" % conn.host)
            except ssl_SSLError:
                conn.close()
                raise
            except socket.error, e:
                err = 0
                if hasattr(e, 'args'):
                    err = getattr(e, 'args')[0]
                else:
                    err = e.errno
                if err == errno.ECONNREFUSED: # Connection refused
                    raise
                if err in (errno.ENETUNREACH, errno.EADDRNOTAVAIL) and i < RETRIES:
                    continue  # retry on potentially transient socket errors
            except httplib.HTTPException:
                # Just because the server closed the connection doesn't apparently mean
                # that the server didn't send a response.
                if hasattr(conn, 'sock') and conn.sock is None:
                    if i < RETRIES-1:
                        conn.close()
                        conn.connect()
                        continue
                    else:
                        conn.close()
                        raise
                if i < RETRIES-1:
                    conn.close()
                    conn.connect()
                    continue 
开发者ID:skarlekar,项目名称:faces,代码行数:44,代码来源:__init__.py


注:本文中的errno.ENETUNREACH属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。