當前位置: 首頁>>代碼示例>>Python>>正文


Python HTTPStatus.TOO_MANY_REQUESTS屬性代碼示例

本文整理匯總了Python中http.HTTPStatus.TOO_MANY_REQUESTS屬性的典型用法代碼示例。如果您正苦於以下問題:Python HTTPStatus.TOO_MANY_REQUESTS屬性的具體用法?Python HTTPStatus.TOO_MANY_REQUESTS怎麽用?Python HTTPStatus.TOO_MANY_REQUESTS使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在http.HTTPStatus的用法示例。


在下文中一共展示了HTTPStatus.TOO_MANY_REQUESTS屬性的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: handle_exception

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import TOO_MANY_REQUESTS [as 別名]
def handle_exception():
    """
    Context manager translating network related exceptions
    to custom :mod:`~galaxy.api.errors`.
    """
    try:
        yield
    except asyncio.TimeoutError:
        raise BackendTimeout()
    except aiohttp.ServerDisconnectedError:
        raise BackendNotAvailable()
    except aiohttp.ClientConnectionError:
        raise NetworkError()
    except aiohttp.ContentTypeError:
        raise UnknownBackendResponse()
    except aiohttp.ClientResponseError as error:
        if error.status == HTTPStatus.UNAUTHORIZED:
            raise AuthenticationRequired()
        if error.status == HTTPStatus.FORBIDDEN:
            raise AccessDenied()
        if error.status == HTTPStatus.SERVICE_UNAVAILABLE:
            raise BackendNotAvailable()
        if error.status == HTTPStatus.TOO_MANY_REQUESTS:
            raise TooManyRequests()
        if error.status >= 500:
            raise BackendError()
        if error.status >= 400:
            logging.warning(
                "Got status %d while performing %s request for %s",
                error.status, error.request_info.method, str(error.request_info.url)
            )
            raise UnknownError()
    except aiohttp.ClientError:
        logging.exception("Caught exception while performing request")
        raise UnknownError() 
開發者ID:TouwaStar,項目名稱:Galaxy_Plugin_Bethesda,代碼行數:37,代碼來源:http.py

示例2: test_delete_repo

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import TOO_MANY_REQUESTS [as 別名]
def test_delete_repo(self):
        """Test delete repo endpoint."""
        resp = self.fetch('/api/v1/repos/myrepo', method='DELETE')
        self.assertTrue(resp.status in [HTTPStatus.OK, HTTPStatus.TOO_MANY_REQUESTS]) 
開發者ID:RedHatInsights,項目名稱:vmaas,代碼行數:6,代碼來源:test_reposcan.py

示例3: test_sync_all

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import TOO_MANY_REQUESTS [as 別名]
def test_sync_all(self):
        """Test sync all endpoint."""
        resp = self.fetch('/api/v1/sync', method='PUT', data="{}")
        self.assertTrue(resp.status in [HTTPStatus.OK, HTTPStatus.TOO_MANY_REQUESTS]) 
開發者ID:RedHatInsights,項目名稱:vmaas,代碼行數:6,代碼來源:test_reposcan.py

示例4: test_sync_repo

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import TOO_MANY_REQUESTS [as 別名]
def test_sync_repo(self):
        """Test sync repo endpoint."""
        resp = self.fetch('/api/v1/sync/repo', method='PUT', data="{}")
        self.assertTrue(resp.status in [HTTPStatus.OK, HTTPStatus.TOO_MANY_REQUESTS]) 
開發者ID:RedHatInsights,項目名稱:vmaas,代碼行數:6,代碼來源:test_reposcan.py

示例5: test_sync_cvemap

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import TOO_MANY_REQUESTS [as 別名]
def test_sync_cvemap(self):
        """Test sync cvemap endpoint."""
        resp = self.fetch('/api/v1/sync/cvemap', method='PUT', data="{}")
        self.assertTrue(resp.status in [HTTPStatus.OK, HTTPStatus.TOO_MANY_REQUESTS]) 
開發者ID:RedHatInsights,項目名稱:vmaas,代碼行數:6,代碼來源:test_reposcan.py

示例6: test_export_pkgtree

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import TOO_MANY_REQUESTS [as 別名]
def test_export_pkgtree(self):
        """Test export_pkgtree endpoint."""
        resp = self.fetch('/api/v1/export/pkgtree', method='PUT', data="{}")
        self.assertTrue(resp.status in [HTTPStatus.OK, HTTPStatus.TOO_MANY_REQUESTS]) 
開發者ID:RedHatInsights,項目名稱:vmaas,代碼行數:6,代碼來源:test_reposcan.py

示例7: test_http_status_to_canonical_code

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import TOO_MANY_REQUESTS [as 別名]
def test_http_status_to_canonical_code(self):
        for status_code, expected in (
            (HTTPStatus.OK, StatusCanonicalCode.OK),
            (HTTPStatus.ACCEPTED, StatusCanonicalCode.OK),
            (HTTPStatus.IM_USED, StatusCanonicalCode.OK),
            (HTTPStatus.MULTIPLE_CHOICES, StatusCanonicalCode.OK),
            (HTTPStatus.BAD_REQUEST, StatusCanonicalCode.INVALID_ARGUMENT),
            (HTTPStatus.UNAUTHORIZED, StatusCanonicalCode.UNAUTHENTICATED),
            (HTTPStatus.FORBIDDEN, StatusCanonicalCode.PERMISSION_DENIED),
            (HTTPStatus.NOT_FOUND, StatusCanonicalCode.NOT_FOUND),
            (
                HTTPStatus.UNPROCESSABLE_ENTITY,
                StatusCanonicalCode.INVALID_ARGUMENT,
            ),
            (
                HTTPStatus.TOO_MANY_REQUESTS,
                StatusCanonicalCode.RESOURCE_EXHAUSTED,
            ),
            (HTTPStatus.NOT_IMPLEMENTED, StatusCanonicalCode.UNIMPLEMENTED),
            (HTTPStatus.SERVICE_UNAVAILABLE, StatusCanonicalCode.UNAVAILABLE),
            (
                HTTPStatus.GATEWAY_TIMEOUT,
                StatusCanonicalCode.DEADLINE_EXCEEDED,
            ),
            (
                HTTPStatus.HTTP_VERSION_NOT_SUPPORTED,
                StatusCanonicalCode.INTERNAL,
            ),
            (600, StatusCanonicalCode.UNKNOWN),
            (99, StatusCanonicalCode.UNKNOWN),
        ):
            with self.subTest(status_code=status_code):
                actual = http_status_to_canonical_code(int(status_code))
                self.assertEqual(actual, expected, status_code) 
開發者ID:open-telemetry,項目名稱:opentelemetry-python,代碼行數:36,代碼來源:test_utils.py

示例8: handle_exception

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import TOO_MANY_REQUESTS [as 別名]
def handle_exception():
    """
    Context manager translating network related exceptions
    to custom :mod:`~galaxy.api.errors`.
    """
    try:
        yield
    except asyncio.TimeoutError:
        raise BackendTimeout()
    except aiohttp.ServerDisconnectedError:
        raise BackendNotAvailable()
    except aiohttp.ClientConnectionError:
        raise NetworkError()
    except aiohttp.ContentTypeError as error:
        raise UnknownBackendResponse(error.message)
    except aiohttp.ClientResponseError as error:
        if error.status == HTTPStatus.UNAUTHORIZED:
            raise AuthenticationRequired(error.message)
        if error.status == HTTPStatus.FORBIDDEN:
            raise AccessDenied(error.message)
        if error.status == HTTPStatus.SERVICE_UNAVAILABLE:
            raise BackendNotAvailable(error.message)
        if error.status == HTTPStatus.TOO_MANY_REQUESTS:
            raise TooManyRequests(error.message)
        if error.status >= 500:
            raise BackendError(error.message)
        if error.status >= 400:
            logger.warning(
                "Got status %d while performing %s request for %s",
                error.status, error.request_info.method, str(error.request_info.url)
            )
            raise UnknownError(error.message)
    except aiohttp.ClientError as e:
        logger.exception("Caught exception while performing request")
        raise UnknownError(repr(e)) 
開發者ID:gogcom,項目名稱:galaxy-integrations-python-api,代碼行數:37,代碼來源:http.py

示例9: set_http_retry_params

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import TOO_MANY_REQUESTS [as 別名]
def set_http_retry_params(
            self,
            retry: bool = True,
            max_attempts: int = 5,
            wait_exponential_multiplier: int = 1000,
            retriable_error_codes: Tuple[HTTPStatus, ...] = (
                HTTPStatus.TOO_MANY_REQUESTS,
                HTTPStatus.REQUEST_TIMEOUT,
                HTTPStatus.SERVICE_UNAVAILABLE,
                HTTPStatus.GATEWAY_TIMEOUT,
            )
        ) -> None:
        '''Sets parameters for HTTP retrying logic. These parameters are passed
        to @retrying.retry which wraps the HTTP requests and retries all
        responses that return an error code defined in |retriable_error_codes|.
        The retrying method uses exponential back off using the multiplier
        |wait_exponential_multiplier| for a max attempts defined by
        |max_attempts|.

        Parameters
        ----------
        retry: bool, optional
            whether HTTP retrying should be performed, if it is set to
            ``False``, the rest of the parameters are ignored.
        max_attempts: int, optional
            the maximum number of request attempts.
        wait_exponential_multiplier: float, optional
            exponential multiplier applied to delay between attempts in ms.
        retriable_error_codes: tuple, optional
            tuple of HTTP error codes to retry if raised.
        '''
        self._http_retry = retry
        if retry:
            self._max_attempts = max_attempts
            self._wait_exponential_multiplier = wait_exponential_multiplier
            self._http_retrable_errors = retriable_error_codes

        else:
            self._max_attempts = 1
            self._wait_exponential_multiplier = 1
            self._http_retrable_errors = () 
開發者ID:MGHComputationalPathology,項目名稱:dicomweb-client,代碼行數:43,代碼來源:api.py

示例10: test_set_http_retry_params

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import TOO_MANY_REQUESTS [as 別名]
def test_set_http_retry_params(httpserver, client):
    retry = True
    retriable_error_codes = (HTTPStatus.TOO_MANY_REQUESTS,
                             HTTPStatus.SERVICE_UNAVAILABLE)
    max_attempts = 10
    wait_exponential_multiplier = 100
    client = DICOMwebClient(httpserver.url)
    client.set_http_retry_params(retry, max_attempts,
                                 wait_exponential_multiplier,
                                 retriable_error_codes)
    assert client._http_retry == retry
    assert client._http_retrable_errors == retriable_error_codes
    assert client._max_attempts == max_attempts
    assert client._wait_exponential_multiplier == wait_exponential_multiplier 
開發者ID:MGHComputationalPathology,項目名稱:dicomweb-client,代碼行數:16,代碼來源:test_api.py


注:本文中的http.HTTPStatus.TOO_MANY_REQUESTS屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。