本文整理匯總了Python中errno.EHOSTUNREACH屬性的典型用法代碼示例。如果您正苦於以下問題:Python errno.EHOSTUNREACH屬性的具體用法?Python errno.EHOSTUNREACH怎麽用?Python errno.EHOSTUNREACH使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類errno
的用法示例。
在下文中一共展示了errno.EHOSTUNREACH屬性的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_connect_ex_error
# 需要導入模塊: import errno [as 別名]
# 或者: from errno import EHOSTUNREACH [as 別名]
def test_connect_ex_error(self):
with support.transient_internet(REMOTE_HOST):
s = ssl.wrap_socket(socket.socket(socket.AF_INET),
cert_reqs=ssl.CERT_REQUIRED,
ca_certs=REMOTE_ROOT_CERT)
try:
rc = s.connect_ex((REMOTE_HOST, 444))
# Issue #19919: Windows machines or VMs hosted on Windows
# machines sometimes return EWOULDBLOCK.
errors = (
errno.ECONNREFUSED, errno.EHOSTUNREACH, errno.ETIMEDOUT,
errno.EWOULDBLOCK,
)
self.assertIn(rc, errors)
finally:
s.close()
示例2: get_a10_client
# 需要導入模塊: import errno [as 別名]
# 或者: from errno import EHOSTUNREACH [as 別名]
def get_a10_client(self, device_info, **kwargs):
if kwargs.get('action', None) == 'create':
retry = [errno.EHOSTUNREACH, errno.ECONNRESET, errno.ECONNREFUSED, errno.ETIMEDOUT]
return acos_client.Client(
device_info['host'], device_info['api_version'],
device_info['username'], device_info['password'],
port=device_info['port'], protocol=device_info['protocol'],
retry_errno_list=retry)
else:
return super(VThunderPerTenantPlumbingHooks, self).get_a10_client(device_info, **kwargs)
示例3: handleCmdConnectFailure
# 需要導入模塊: import errno [as 別名]
# 或者: from errno import EHOSTUNREACH [as 別名]
def handleCmdConnectFailure(self, failure):
log.error("CMD CONNECT: %s" % failure.getErrorMessage())
# Map common twisted errors to SOCKS error codes
if failure.type == error.NoRouteError:
self.sendReply(SOCKSv5Reply.NetworkUnreachable)
elif failure.type == error.ConnectionRefusedError:
self.sendReply(SOCKSv5Reply.ConnectionRefused)
elif failure.type == error.TCPTimedOutError or failure.type == error.TimeoutError:
self.sendReply(SOCKSv5Reply.TTLExpired)
elif failure.type == error.UnsupportedAddressFamily:
self.sendReply(SOCKSv5Reply.AddressTypeNotSupported)
elif failure.type == error.ConnectError:
# Twisted doesn't have a exception defined for EHOSTUNREACH,
# so the failure is a ConnectError. Try to catch this case
# and send a better reply, but fall back to a GeneralFailure.
reply = SOCKSv5Reply.GeneralFailure
try:
import errno
if hasattr(errno, "EHOSTUNREACH"):
if failure.value.osError == errno.EHOSTUNREACH:
reply = SOCKSv5Reply.HostUnreachable
if hasattr(errno, "WSAEHOSTUNREACH"):
if failure.value.osError == errno.WSAEHOSTUNREACH:
reply = SOCKSv5Reply.HostUnreachable
except Exception:
pass
self.sendReply(reply)
else:
self.sendReply(SOCKSv5Reply.GeneralFailure)
failure.trap(error.NoRouteError, error.ConnectionRefusedError,
error.TCPTimedOutError, error.TimeoutError,
error.UnsupportedAddressFamily, error.ConnectError)
示例4: test_inconsistent_folder_no_network
# 需要導入模塊: import errno [as 別名]
# 或者: from errno import EHOSTUNREACH [as 別名]
def test_inconsistent_folder_no_network(base_mountpoint, running_backend, alice_user_fs):
async with mountpoint_manager_factory(
alice_user_fs, alice_user_fs.event_bus, base_mountpoint
) as alice_mountpoint_manager:
workspace = await create_inconsistent_workspace(alice_user_fs)
mountpoint_path = await alice_mountpoint_manager.mount_workspace(workspace.workspace_id)
with running_backend.offline():
await trio.to_thread.run_sync(
_os_tests, mountpoint_path, errno.EHOSTUNREACH, WINDOWS_ERROR_HOST_UNREACHABLE
)
示例5: handle_write_event
# 需要導入模塊: import errno [as 別名]
# 或者: from errno import EHOSTUNREACH [as 別名]
def handle_write_event(self):
if _debug: TCPClient._debug("handle_write_event")
# there might be an error
err = self.socket.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR)
if _debug: TCPClient._debug(" - err: %r", err)
# check for connection refused
if err == 0:
if not self.connected:
if _debug: TCPClient._debug(" - connected")
self.handle_connect()
else:
if _debug: TCPClient._debug(" - peer: %r", self.peer)
if (err == errno.ECONNREFUSED):
socket_error = socket.error(err, "connection refused")
elif (err == errno.ETIMEDOUT):
socket_error = socket.error(err, "timed out")
elif (err == errno.EHOSTUNREACH):
socket_error = socket.error(err, "host unreachable")
else:
socket_error = socket.error(err, "other unknown: %r" % (err,))
if _debug: TCPClient._debug(" - socket_error: %r", socket_error)
self.handle_error(socket_error)
return
# pass along
asyncore.dispatcher.handle_write_event(self)
示例6: test_connect_ex_error
# 需要導入模塊: import errno [as 別名]
# 或者: from errno import EHOSTUNREACH [as 別名]
def test_connect_ex_error(self):
server = socket.socket(socket.AF_INET)
self.addCleanup(server.close)
port = support.bind_port(server) # Reserve port but don't listen
s = test_wrap_socket(socket.socket(socket.AF_INET),
cert_reqs=ssl.CERT_REQUIRED)
self.addCleanup(s.close)
rc = s.connect_ex((HOST, port))
# Issue #19919: Windows machines or VMs hosted on Windows
# machines sometimes return EWOULDBLOCK.
errors = (
errno.ECONNREFUSED, errno.EHOSTUNREACH, errno.ETIMEDOUT,
errno.EWOULDBLOCK,
)
self.assertIn(rc, errors)
示例7: wait_for_sshd
# 需要導入模塊: import errno [as 別名]
# 或者: from errno import EHOSTUNREACH [as 別名]
def wait_for_sshd(cls, vm_id):
"""Insist on having the vm booted and sshd
listening"""
cls.echo('Waiting for the vm to come online')
version, ip_addr = cls.vm_ip(vm_id)
give_up = time.time() + 300
last_error = None
while time.time() < give_up:
try:
inet = socket.AF_INET
if version == 6:
inet = socket.AF_INET6
sd = socket.socket(inet, socket.SOCK_STREAM,
socket.IPPROTO_TCP)
sd.settimeout(5)
sd.connect((ip_addr, 22))
sd.recv(1024)
return
except socket.error as err:
if err.errno == errno.EHOSTUNREACH and version == 6:
cls.error('%s is not reachable, you may be missing '
'IPv6 connectivity' % ip_addr)
last_error = err
time.sleep(1)
except Exception as err:
last_error = err
time.sleep(1)
cls.error('VM did not spin up (last error: %s)' % last_error)