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


Python errno.ECONNRESET属性代码示例

本文整理汇总了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 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:23,代码来源:test_http.py

示例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 
开发者ID:cherrypy,项目名称:cherrypy,代码行数:19,代码来源:test_http.py

示例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 
开发者ID:sippy,项目名称:rtp_cluster,代码行数:27,代码来源:DNRelay.py

示例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. 
开发者ID:glmcdona,项目名称:meddle,代码行数:22,代码来源:xmlrpclib.py

示例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) 
开发者ID:einstein95,项目名称:crunchy-xml-decoder,代码行数:21,代码来源:hls.py

示例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) 
开发者ID:sippy,项目名称:rtp_cluster,代码行数:38,代码来源:Rtp_proxy_client_stream.py

示例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 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:13,代码来源:client.py

示例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) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:34,代码来源:iostream.py

示例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) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:9,代码来源:iostream.py

示例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) 
开发者ID:jpush,项目名称:jbox,代码行数:35,代码来源:sync.py

示例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) 
开发者ID:jpush,项目名称:jbox,代码行数:39,代码来源:gthread.py

示例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!") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:34,代码来源:test_ssl.py

示例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 
开发者ID:XiaoMi,项目名称:galaxy-sdk-python,代码行数:17,代码来源:TSocket.py

示例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
        ) 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:11,代码来源:iostream.py

示例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) 
开发者ID:a10networks,项目名称:a10-neutron-lbaas,代码行数:12,代码来源:vthunder_per_tenant.py


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