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


Python http_client.BadStatusLine方法代码示例

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


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

示例1: get

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import BadStatusLine [as 别名]
def get(self, path, as_json=False, attempts=25):
        """ Queries the server using requests.GET and returns the response object. 
        
        Parameters
        ----------
        path :  `str`
            Path to the resource, relative to 'http://hostname:port/'
        as_json :  `bool`
            Returns the json object if True. Defaults to False.
        attempts: `int`
            This function will retry up to `attempts` times on connection errors, to handle 
            the server still waking up. Defaults to 25.
        """
        e = None
        for i in range(attempts):
            try:
                with self.handle_proxy():
                    returned = requests.get('http://%s:%d/%s' % (self.hostname, self.port, path))
                return returned.json() if as_json else returned
            except (http_client.BadStatusLine, requests.ConnectionError) as e:
                time.sleep(int(i) / 10)
                pass
        raise e 
开发者ID:man-group,项目名称:pytest-plugins,代码行数:25,代码来源:http.py

示例2: post

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import BadStatusLine [as 别名]
def post(self, path, data=None, attempts=25, as_json=False, headers=None):
        """ Posts data to the server using requests.POST and returns the response object. 
        
        Parameters
        ----------
        path :  `str`
            Path to the resource, relative to 'http://hostname:port/'
        as_json :  `bool`
            Returns the json response if True. Defaults to False.
        attempts: `int`
            This function will retry up to `attempts` times on connection errors, to handle 
            the server still waking up. Defaults to 25.
        headers: `dict`
            Optional HTTP headers.
        """
        e = None
        for i in range(attempts):
            try:
                with self.handle_proxy():
                    returned = requests.post('http://%s:%d/%s' % (self.hostname, self.port, path), data=data, headers=headers)
                return returned.json() if as_json else returned
            except (http_client.BadStatusLine, requests.ConnectionError) as e:
                time.sleep(int(i) / 10)
                pass
        raise e 
开发者ID:man-group,项目名称:pytest-plugins,代码行数:27,代码来源:http.py

示例3: open_url

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import BadStatusLine [as 别名]
def open_url(self, url, warning=None):
        if url.startswith('file:'):
            return local_open(url)
        try:
            return open_with_auth(url, self.opener)
        except (ValueError, http_client.InvalidURL) as v:
            msg = ' '.join([str(arg) for arg in v.args])
            if warning:
                self.warn(warning, msg)
            else:
                raise DistutilsError('%s %s' % (url, msg))
        except urllib.error.HTTPError as v:
            return v
        except urllib.error.URLError as v:
            if warning:
                self.warn(warning, v.reason)
            else:
                raise DistutilsError("Download error for %s: %s"
                                     % (url, v.reason))
        except http_client.BadStatusLine as v:
            if warning:
                self.warn(warning, v.line)
            else:
                raise DistutilsError(
                    '%s returned a bad status line. The server might be '
                    'down, %s' %
                    (url, v.line)
                )
        except (http_client.HTTPException, socket.error) as v:
            if warning:
                self.warn(warning, v)
            else:
                raise DistutilsError("Download error for %s: %s"
                                     % (url, v)) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:36,代码来源:package_index.py

示例4: test_read_non_integer_code

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import BadStatusLine [as 别名]
def test_read_non_integer_code():
    with pytest.raises(BadStatusLine):
        build_response(content, code='X') 
开发者ID:eBay,项目名称:wextracto,代码行数:5,代码来源:test_response.py

示例5: test_read_bad_protocol_version

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import BadStatusLine [as 别名]
def test_read_bad_protocol_version():
    with pytest.raises(BadStatusLine):
        build_response(content, protocol_version='HTTP/X') 
开发者ID:eBay,项目名称:wextracto,代码行数:5,代码来源:test_response.py

示例6: hypervisorHeartbeat

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import BadStatusLine [as 别名]
def hypervisorHeartbeat(self, config, options=None):
        """
        Send heart beat to candlepin server
        :param config: reference on configuration
        :param options: other options
        """
        if options:
            named_options = NamedOptions()
            for key, value in options['global'].items():
                setattr(named_options, key, value)
        else:
            named_options = None

        try:
            connection = self._connect(config)
            result = connection.hypervisorHeartbeat(config['owner'], named_options)
        except BadStatusLine:
            raise ManagerError("Communication with subscription manager interrupted")
        except rhsm_connection.RateLimitExceededException as e:
            raise ManagerThrottleError(e.retry_after)
        except rhsm_connection.GoneException:
            raise ManagerError("Communication with subscription manager failed: consumer no longer exists")
        except rhsm_connection.ConnectionException as e:
            if hasattr(e, 'code'):
                raise ManagerError("Communication with subscription manager failed with code %d: %s" % (e.code, str(e)))
            raise ManagerError("Communication with subscription manager failed: %s" % str(e))

        return result 
开发者ID:candlepin,项目名称:virt-who,代码行数:30,代码来源:subscriptionmanager.py

示例7: check_report_state

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import BadStatusLine [as 别名]
def check_report_state(self, report):
        # BZ 1554228
        job_id = str(report.job_id)
        self._connect(report.config)
        self.logger.debug('Checking status of job %s', job_id)
        try:
            result = self.connection.getJob(job_id)
        except BadStatusLine:
            raise ManagerError("Communication with subscription manager interrupted")
        except rhsm_connection.RateLimitExceededException as e:
            raise ManagerThrottleError(e.retry_after)
        except rhsm_connection.ConnectionException as e:
            if hasattr(e, 'code'):
                raise ManagerError("Communication with subscription manager failed with code %d: %s" % (e.code, str(e)))
            raise ManagerError("Communication with subscription manager failed: %s" % str(e))
        state = STATE_MAPPING.get(result['state'], AbstractVirtReport.STATE_FAILED)
        report.state = state
        if state not in (AbstractVirtReport.STATE_FINISHED,
                         AbstractVirtReport.STATE_CANCELED,
                         AbstractVirtReport.STATE_FAILED):
            self.logger.debug('Job %s not finished', job_id)
        else:
            # log completed job status
            result_data = result.get('resultData', {})
            if not result_data:
                self.logger.warning("Job status report without resultData: %s", result)
                return
            if isinstance(result_data, string_types):
                self.logger.warning("Job status report encountered the following error: %s", result_data)
                return
            for fail in result_data.get('failedUpdate', []):
                self.logger.error("Error during update list of guests: %s", str(fail))
            self.logger.debug("Number of mappings unchanged: %d", len(result_data.get('unchanged', [])))
            self.logger.info("Mapping for config \"%s\" updated", report.config.name) 
开发者ID:candlepin,项目名称:virt-who,代码行数:36,代码来源:subscriptionmanager.py

示例8: testDefaultExceptionHandler

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import BadStatusLine [as 别名]
def testDefaultExceptionHandler(self):
        """Ensures exception handles swallows (retries)"""
        mock_http_content = 'content'.encode('utf8')
        for exception_arg in (
                http_client.BadStatusLine('line'),
                http_client.IncompleteRead('partial'),
                http_client.ResponseNotReady(),
                socket.error(),
                socket.gaierror(),
                httplib2.ServerNotFoundError(),
                ValueError(),
                exceptions.RequestError(),
                exceptions.BadStatusCodeError(
                    {'status': 503}, mock_http_content, 'url'),
                exceptions.RetryAfterError(
                    {'status': 429}, mock_http_content, 'url', 0)):

            retry_args = http_wrapper.ExceptionRetryArgs(
                http={'connections': {}}, http_request=_MockHttpRequest(),
                exc=exception_arg, num_retries=0, max_retry_wait=0,
                total_wait_sec=0)

            # Disable time.sleep for this handler as it is called with
            # a minimum value of 1 second.
            with patch('time.sleep', return_value=None):
                http_wrapper.HandleExceptionsAndRebuildHttpConnections(
                    retry_args) 
开发者ID:google,项目名称:apitools,代码行数:29,代码来源:http_wrapper_test.py

示例9: hypervisorCheckIn

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import BadStatusLine [as 别名]
def hypervisorCheckIn(self, report, options=None):
        """ Send hosts to guests mapping to subscription manager. """
        connection = self._connect(report.config)

        is_async = self._is_rhsm_server_async(report, connection)
        serialized_mapping = self._hypervisor_mapping(report, is_async, connection)
        self.logger.debug("Host-to-guest mapping being sent to '{owner}': {mapping}".format(
                          owner=report.config['owner'],
                          mapping=json.dumps(serialized_mapping, indent=4)))

        # All subclasses of ConfigSection use dictionary like notation,
        # but RHSM uses attribute like notation
        if options:
            named_options = NamedOptions()
            for key, value in options['global'].items():
                setattr(named_options, key, value)
        else:
            named_options = None

        try:
            try:
                result = self.connection.hypervisorCheckIn(
                    report.config['owner'],
                    '',
                    serialized_mapping,
                    options=named_options)  # pylint:disable=unexpected-keyword-arg
            except TypeError:
                # This is temporary workaround until the options parameter gets implemented
                # in python-rhsm
                self.logger.debug(
                    "hypervisorCheckIn method in python-rhsm doesn't understand options parameter, ignoring"
                )
                result = self.connection.hypervisorCheckIn(report.config['owner'], '', serialized_mapping)
        except BadStatusLine:
            raise ManagerError("Communication with subscription manager interrupted")
        except rhsm_connection.RateLimitExceededException as e:
            raise ManagerThrottleError(e.retry_after)
        except rhsm_connection.GoneException:
            raise ManagerError("Communication with subscription manager failed: consumer no longer exists")
        except rhsm_connection.ConnectionException as e:
            if hasattr(e, 'code'):
                raise ManagerError("Communication with subscription manager failed with code %d: %s" % (e.code, str(e)))
            raise ManagerError("Communication with subscription manager failed: %s" % str(e))

        if is_async is True:
            report.state = AbstractVirtReport.STATE_CREATED
            report.job_id = result['id']
        else:
            report.state = AbstractVirtReport.STATE_FINISHED
        return result 
开发者ID:candlepin,项目名称:virt-who,代码行数:52,代码来源:subscriptionmanager.py

示例10: HandleExceptionsAndRebuildHttpConnections

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import BadStatusLine [as 别名]
def HandleExceptionsAndRebuildHttpConnections(retry_args):
    """Exception handler for http failures.

    This catches known failures and rebuilds the underlying HTTP connections.

    Args:
      retry_args: An ExceptionRetryArgs tuple.
    """
    # If the server indicates how long to wait, use that value.  Otherwise,
    # calculate the wait time on our own.
    retry_after = None

    # Transport failures
    if isinstance(retry_args.exc, (http_client.BadStatusLine,
                                   http_client.IncompleteRead,
                                   http_client.ResponseNotReady)):
        logging.debug('Caught HTTP error %s, retrying: %s',
                      type(retry_args.exc).__name__, retry_args.exc)
    elif isinstance(retry_args.exc, socket.error):
        logging.debug('Caught socket error, retrying: %s', retry_args.exc)
    elif isinstance(retry_args.exc, socket.gaierror):
        logging.debug(
            'Caught socket address error, retrying: %s', retry_args.exc)
    elif isinstance(retry_args.exc, socket.timeout):
        logging.debug(
            'Caught socket timeout error, retrying: %s', retry_args.exc)
    elif isinstance(retry_args.exc, httplib2.ServerNotFoundError):
        logging.debug(
            'Caught server not found error, retrying: %s', retry_args.exc)
    elif isinstance(retry_args.exc, ValueError):
        # oauth2client tries to JSON-decode the response, which can result
        # in a ValueError if the response was invalid. Until that is fixed in
        # oauth2client, need to handle it here.
        logging.debug('Response content was invalid (%s), retrying',
                      retry_args.exc)
    elif (isinstance(retry_args.exc, TokenRefreshError) and
          hasattr(retry_args.exc, 'status') and
          (retry_args.exc.status == TOO_MANY_REQUESTS or
           retry_args.exc.status >= 500)):
        logging.debug(
            'Caught transient credential refresh error (%s), retrying',
            retry_args.exc)
    elif isinstance(retry_args.exc, exceptions.RequestError):
        logging.debug('Request returned no response, retrying')
    # API-level failures
    elif isinstance(retry_args.exc, exceptions.BadStatusCodeError):
        logging.debug('Response returned status %s, retrying',
                      retry_args.exc.status_code)
    elif isinstance(retry_args.exc, exceptions.RetryAfterError):
        logging.debug('Response returned a retry-after header, retrying')
        retry_after = retry_args.exc.retry_after
    else:
        raise retry_args.exc
    RebuildHttpConnections(retry_args.http)
    logging.debug('Retrying request to url %s after exception %s',
                  retry_args.http_request.url, retry_args.exc)
    time.sleep(
        retry_after or util.CalculateWaitForRetry(
            retry_args.num_retries, max_wait=retry_args.max_retry_wait)) 
开发者ID:google,项目名称:apitools,代码行数:61,代码来源:http_wrapper.py

示例11: test_2_KeyboardInterrupt

# 需要导入模块: from six.moves import http_client [as 别名]
# 或者: from six.moves.http_client import BadStatusLine [as 别名]
def test_2_KeyboardInterrupt(self):
        # Raise a keyboard interrupt in the HTTP server's main thread.
        # We must start the server in this, the main thread
        engine.start()
        cherrypy.server.start()

        self.persistent = True
        try:
            # Make the first request and assert there's no "Connection: close".
            self.getPage('/')
            self.assertStatus('200 OK')
            self.assertBody('Hello World')
            self.assertNoHeader('Connection')

            cherrypy.server.httpserver.interrupt = KeyboardInterrupt
            engine.block()

            self.assertEqual(db_connection.running, False)
            self.assertEqual(len(db_connection.threads), 0)
            self.assertEqual(engine.state, engine.states.EXITING)
        finally:
            self.persistent = False

        # Raise a keyboard interrupt in a page handler; on multithreaded
        # servers, this should occur in one of the worker threads.
        # This should raise a BadStatusLine error, since the worker
        # thread will just die without writing a response.
        engine.start()
        cherrypy.server.start()
        # From python3.5 a new exception is retuned when the connection
        # ends abruptly:
        #   http.client.RemoteDisconnected
        # RemoteDisconnected is a subclass of:
        #   (ConnectionResetError, http.client.BadStatusLine)
        # and ConnectionResetError is an indirect subclass of:
        #    OSError
        # From python 3.3 an up socket.error is an alias to OSError
        # following PEP-3151, therefore http.client.RemoteDisconnected
        # is considered a socket.error.
        #
        # raise_subcls specifies the classes that are not going
        # to be considered as a socket.error for the retries.
        # Given that RemoteDisconnected is part BadStatusLine
        # we can use the same call for all py3 versions without
        # sideffects. python < 3.5 will raise directly BadStatusLine
        # which is not a subclass for socket.error/OSError.
        try:
            self.getPage('/ctrlc', raise_subcls=BadStatusLine)
        except BadStatusLine:
            pass
        else:
            print(self.body)
            self.fail('AssertionError: BadStatusLine not raised')

        engine.block()
        self.assertEqual(db_connection.running, False)
        self.assertEqual(len(db_connection.threads), 0) 
开发者ID:Tautulli,项目名称:Tautulli,代码行数:59,代码来源:test_states.py


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