本文整理汇总了Python中errno.ECONNRESET属性的典型用法代码示例。如果您正苦于以下问题:Python errno.ECONNRESET属性的具体用法?Python errno.ECONNRESET怎么用?Python errno.ECONNRESET使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类errno
的用法示例。
在下文中一共展示了errno.ECONNRESET属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_http_over_https
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ECONNRESET [as 别名]
def test_http_over_https(self):
if self.scheme != 'https':
return self.skip('skipped (not running HTTPS)... ')
# Try connecting without SSL.
conn = HTTPConnection('%s:%s' % (self.interface(), self.PORT))
conn.putrequest('GET', '/', skip_host=True)
conn.putheader('Host', self.HOST)
conn.endheaders()
response = conn.response_class(conn.sock, method='GET')
try:
response.begin()
self.assertEqual(response.status, 400)
self.body = response.read()
self.assertBody('The client sent a plain HTTP request, but this '
'server only speaks HTTPS on this port.')
except socket.error:
e = sys.exc_info()[1]
# "Connection reset by peer" is also acceptable.
if e.errno != errno.ECONNRESET:
raise
示例2: test_garbage_in
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ECONNRESET [as 别名]
def test_garbage_in(self):
# Connect without SSL regardless of server.scheme
c = HTTPConnection('%s:%s' % (self.interface(), self.PORT))
c._output(b'gjkgjklsgjklsgjkljklsg')
c._send_output()
response = c.response_class(c.sock, method='GET')
try:
response.begin()
self.assertEqual(response.status, 400)
self.assertEqual(response.fp.read(22),
b'Malformed Request-Line')
c.close()
except socket.error:
e = sys.exc_info()[1]
# "Connection reset by peer" is also acceptable.
if e.errno != errno.ECONNRESET:
raise
示例3: deliver_dnotify
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ECONNRESET [as 别名]
def deliver_dnotify(self, dnstring, _recurse = 0):
if self.s == None:
self.connect()
if _recurse > _MAX_RECURSE:
raise Exception('Cannot reconnect: %s', self.spath)
if not dnstring.endswith('\n'):
dnstring += '\n'
while True:
try:
self.s.send(dnstring)
break
except socket.error as why:
if why[0] == EINTR:
continue
elif why[0] in (EPIPE, ENOTCONN, ECONNRESET):
self.s = None
return self.deliver_dnotify(dnstring, _recurse + 1)
raise why
# Clean any incoming data on the socket
if len(self.poller.poll(0)) > 0:
try:
self.s.recv(1024)
except:
pass
return
示例4: request
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ECONNRESET [as 别名]
def request(self, host, handler, request_body, verbose=0):
#retry request once if cached connection has gone cold
for i in (0, 1):
try:
return self.single_request(host, handler, request_body, verbose)
except socket.error, e:
if i or e.errno not in (errno.ECONNRESET, errno.ECONNABORTED, errno.EPIPE):
raise
except httplib.BadStatusLine: #close after we sent request
if i:
raise
##
# Send a complete request, and parse the response.
#
# @param host Target host.
# @param handler Target PRC handler.
# @param request_body XML-RPC request body.
# @param verbose Debugging flag.
# @return Parsed response.
示例5: read
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ECONNRESET [as 别名]
def read(self, n):
buffer = []
while self.offset < self.file_size:
try:
data = self.stream.read(min(n, self.file_size - self.offset))
self.offset += len(data)
n -= len(data)
buffer.append(data)
if n == 0 or data:
break
except socket.timeout:
self._progress()
self._restart()
except socket.error as e:
if e.errno != errno.ECONNRESET:
raise
self._progress()
self._restart()
return "".join(buffer)
示例6: send_raw
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ECONNRESET [as 别名]
def send_raw(self, command, _recurse = 0, stime = None):
if _recurse > _MAX_RECURSE:
raise Exception('Cannot reconnect: %s' % (str(self.userv.address),))
if self.s == None:
self.connect()
#print('%s.send_raw(%s)' % (id(self), command))
if stime == None:
stime = MonoTime()
while True:
try:
self.s.send(command.encode())
break
except socket.error as why:
if why.errno == EINTR:
continue
elif why.errno in (EPIPE, ENOTCONN, ECONNRESET):
self.s = None
return self.send_raw(command, _recurse + 1, stime)
raise why
while True:
try:
rval = self.s.recv(1024)
if len(rval) == 0:
self.s = None
return self.send_raw(command, _MAX_RECURSE, stime)
rval = rval.decode().strip()
break
except socket.error as why:
if why.errno == EINTR:
continue
elif why.errno in (EPIPE, ENOTCONN, ECONNRESET):
self.s = None
return self.send_raw(command, _recurse + 1, stime)
raise why
rtpc_delay = stime.offsetFromNow()
return (rval, rtpc_delay)
示例7: request
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ECONNRESET [as 别名]
def request(self, host, handler, request_body, verbose=False):
#retry request once if cached connection has gone cold
for i in (0, 1):
try:
return self.single_request(host, handler, request_body, verbose)
except socket.error as e:
if i or e.errno not in (errno.ECONNRESET, errno.ECONNABORTED, errno.EPIPE):
raise
except http_client.BadStatusLine: #close after we sent request
if i:
raise
示例8: _read_to_buffer
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ECONNRESET [as 别名]
def _read_to_buffer(self):
"""Reads from the socket and appends the result to the read buffer.
Returns the number of bytes read. Returns 0 if there is nothing
to read (i.e. the read returns EWOULDBLOCK or equivalent). On
error closes the socket and raises an exception.
"""
while True:
try:
chunk = self.read_from_fd()
except (socket.error, IOError, OSError) as e:
if errno_from_exception(e) == errno.EINTR:
continue
# ssl.SSLError is a subclass of socket.error
if self._is_connreset(e):
# Treat ECONNRESET as a connection close rather than
# an error to minimize log spam (the exception will
# be available on self.error for apps that care).
self.close(exc_info=True)
return
self.close(exc_info=True)
raise
break
if chunk is None:
return 0
self._read_buffer.append(chunk)
self._read_buffer_size += len(chunk)
if self._read_buffer_size > self.max_buffer_size:
gen_log.error("Reached maximum read buffer size")
self.close()
raise StreamBufferFullError("Reached maximum read buffer size")
return len(chunk)
示例9: _is_connreset
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ECONNRESET [as 别名]
def _is_connreset(self, exc):
"""Return true if exc is ECONNRESET or equivalent.
May be overridden in subclasses.
"""
return (isinstance(exc, (socket.error, IOError)) and
errno_from_exception(exc) in _ERRNO_CONNRESET)
示例10: handle
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ECONNRESET [as 别名]
def handle(self, listener, client, addr):
req = None
try:
if self.cfg.is_ssl:
client = ssl.wrap_socket(client, server_side=True,
**self.cfg.ssl_options)
parser = http.RequestParser(self.cfg, client)
req = six.next(parser)
self.handle_request(listener, req, client, addr)
except http.errors.NoMoreData as e:
self.log.debug("Ignored premature client disconnection. %s", e)
except StopIteration as e:
self.log.debug("Closing connection. %s", e)
except ssl.SSLError as e:
if e.args[0] == ssl.SSL_ERROR_EOF:
self.log.debug("ssl connection closed")
client.close()
else:
self.log.debug("Error processing SSL request.")
self.handle_error(req, client, addr, e)
except EnvironmentError as e:
if e.errno not in (errno.EPIPE, errno.ECONNRESET):
self.log.exception("Socket error processing request.")
else:
if e.errno == errno.ECONNRESET:
self.log.debug("Ignoring connection reset")
else:
self.log.debug("Ignoring EPIPE")
except Exception as e:
self.handle_error(req, client, addr, e)
finally:
util.close(client)
示例11: handle
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ECONNRESET [as 别名]
def handle(self, conn):
keepalive = False
req = None
try:
req = six.next(conn.parser)
if not req:
return (False, conn)
# handle the request
keepalive = self.handle_request(req, conn)
if keepalive:
return (keepalive, conn)
except http.errors.NoMoreData as e:
self.log.debug("Ignored premature client disconnection. %s", e)
except StopIteration as e:
self.log.debug("Closing connection. %s", e)
except ssl.SSLError as e:
if e.args[0] == ssl.SSL_ERROR_EOF:
self.log.debug("ssl connection closed")
conn.sock.close()
else:
self.log.debug("Error processing SSL request.")
self.handle_error(req, conn.sock, conn.client, e)
except EnvironmentError as e:
if e.errno not in (errno.EPIPE, errno.ECONNRESET):
self.log.exception("Socket error processing request.")
else:
if e.errno == errno.ECONNRESET:
self.log.debug("Ignoring connection reset")
else:
self.log.debug("Ignoring connection epipe")
except Exception as e:
self.handle_error(req, conn.sock, conn.client, e)
return (False, conn)
示例12: test_wrong_cert
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ECONNRESET [as 别名]
def test_wrong_cert(self):
"""Connecting when the server rejects the client's certificate
Launch a server with CERT_REQUIRED, and check that trying to
connect to it with a wrong client certificate fails.
"""
certfile = os.path.join(os.path.dirname(__file__) or os.curdir,
"keycert.pem")
server = ThreadedEchoServer(SIGNED_CERTFILE,
certreqs=ssl.CERT_REQUIRED,
cacerts=SIGNING_CA, chatty=False,
connectionchatty=False)
with server, \
closing(socket.socket()) as sock, \
closing(ssl.wrap_socket(sock,
certfile=certfile,
ssl_version=ssl.PROTOCOL_TLSv1)) as s:
try:
# Expect either an SSL error about the server rejecting
# the connection, or a low-level connection reset (which
# sometimes happens on Windows)
s.connect((HOST, server.port))
except ssl.SSLError as e:
if support.verbose:
sys.stdout.write("\nSSLError is %r\n" % e)
except socket.error as e:
if e.errno != errno.ECONNRESET:
raise
if support.verbose:
sys.stdout.write("\nsocket.error is %r\n" % e)
else:
self.fail("Use of invalid cert should have failed!")
示例13: read
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ECONNRESET [as 别名]
def read(self, sz):
try:
buff = self.handle.recv(sz)
except socket.error, e:
if (e.args[0] == errno.ECONNRESET and
(sys.platform == 'darwin' or sys.platform.startswith('freebsd'))):
# freebsd and Mach don't follow POSIX semantic of recv
# and fail with ECONNRESET if peer performed shutdown.
# See corresponding comment and code in TSocket::read()
# in lib/cpp/src/transport/TSocket.cpp.
self.close()
# Trigger the check to raise the END_OF_FILE exception below.
buff = ''
else:
raise
示例14: _is_connreset
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ECONNRESET [as 别名]
def _is_connreset(self, exc: BaseException) -> bool:
"""Return ``True`` if exc is ECONNRESET or equivalent.
May be overridden in subclasses.
"""
return (
isinstance(exc, (socket.error, IOError))
and errno_from_exception(exc) in _ERRNO_CONNRESET
)
示例15: get_a10_client
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ECONNRESET [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)