Python http.HTTPStatus.TOO_MANY_REQUESTS Examples
The following are 10
code examples of http.HTTPStatus.TOO_MANY_REQUESTS().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
http.HTTPStatus
, or try the search function
.
Example #1
Source File: http.py From Galaxy_Plugin_Bethesda with MIT License | 5 votes |
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()
Example #2
Source File: test_reposcan.py From vmaas with GNU General Public License v2.0 | 5 votes |
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])
Example #3
Source File: test_reposcan.py From vmaas with GNU General Public License v2.0 | 5 votes |
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])
Example #4
Source File: test_reposcan.py From vmaas with GNU General Public License v2.0 | 5 votes |
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])
Example #5
Source File: test_reposcan.py From vmaas with GNU General Public License v2.0 | 5 votes |
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])
Example #6
Source File: test_reposcan.py From vmaas with GNU General Public License v2.0 | 5 votes |
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])
Example #7
Source File: test_utils.py From opentelemetry-python with Apache License 2.0 | 5 votes |
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)
Example #8
Source File: http.py From galaxy-integrations-python-api with MIT License | 5 votes |
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))
Example #9
Source File: api.py From dicomweb-client with MIT License | 5 votes |
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 = ()
Example #10
Source File: test_api.py From dicomweb-client with MIT License | 5 votes |
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