Python http.HTTPStatus.SERVICE_UNAVAILABLE Examples
The following are 9
code examples of http.HTTPStatus.SERVICE_UNAVAILABLE().
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: backend.py From galaxy_blizzard_plugin with MIT License | 5 votes |
def handle_status_code(status_code): logging.debug(f'Status code: {status_code}') if status_code == HTTPStatus.UNAUTHORIZED: raise AuthenticationRequired() if status_code == HTTPStatus.FORBIDDEN: raise AccessDenied() if status_code == HTTPStatus.SERVICE_UNAVAILABLE: raise BackendNotAvailable() if status_code >= 500: raise BackendError() if status_code >= 400: raise UnknownError()
Example #2
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 #3
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 #4
Source File: test_aiohttp_client_integration.py From opentelemetry-python with Apache License 2.0 | 5 votes |
def test_status_codes(self): for status_code, span_status in ( (HTTPStatus.OK, StatusCanonicalCode.OK), (HTTPStatus.TEMPORARY_REDIRECT, StatusCanonicalCode.OK), (HTTPStatus.SERVICE_UNAVAILABLE, StatusCanonicalCode.UNAVAILABLE), ( HTTPStatus.GATEWAY_TIMEOUT, StatusCanonicalCode.DEADLINE_EXCEEDED, ), ): with self.subTest(status_code=status_code): host, port = self._http_request( trace_config=opentelemetry.ext.aiohttp_client.create_trace_config(), url="/test-path?query=param#foobar", status_code=status_code, ) self.assert_spans( [ ( "GET", (span_status, None), { "component": "http", "http.method": "GET", "http.url": "http://{}:{}/test-path?query=param#foobar".format( host, port ), "http.status_code": int(status_code), "http.status_text": status_code.phrase, }, ) ] ) self.memory_exporter.clear()
Example #5
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 #6
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 #7
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
Example #8
Source File: client.py From nacos-sdk-python with Apache License 2.0 | 4 votes |
def _do_sync_req(self, url, headers=None, params=None, data=None, timeout=None, method="GET"): url = "?".join([url, urlencode(params)]) if params else url all_headers = self._get_common_headers(params, data) if headers: all_headers.update(headers) logger.debug( "[do-sync-req] url:%s, headers:%s, params:%s, data:%s, timeout:%s" % ( url, all_headers, params, data, timeout)) tries = 0 while True: try: server_info = self.get_server() if not server_info: logger.error("[do-sync-req] can not get one server.") raise NacosRequestException("Server is not available.") address, port = server_info server = ":".join([address, str(port)]) server_url = "%s://%s" % ("http", server) if python_version_bellow("3"): req = Request(url=server_url + url, data=urlencode(data).encode() if data else None, headers=all_headers) req.get_method = lambda: method else: req = Request(url=server_url + url, data=urlencode(data).encode() if data else None, headers=all_headers, method=method) # for python version compatibility if python_version_bellow("2.7.9"): resp = urlopen(req, timeout=timeout) else: resp = urlopen(req, timeout=timeout, context=None) logger.debug("[do-sync-req] info from server:%s" % server) return resp except HTTPError as e: if e.code in [HTTPStatus.INTERNAL_SERVER_ERROR, HTTPStatus.BAD_GATEWAY, HTTPStatus.SERVICE_UNAVAILABLE]: logger.warning("[do-sync-req] server:%s is not available for reason:%s" % (server, e.msg)) else: raise except socket.timeout: logger.warning("[do-sync-req] %s request timeout" % server) except URLError as e: logger.warning("[do-sync-req] %s connection error:%s" % (server, e.reason)) tries += 1 if tries >= len(self.server_list): logger.error("[do-sync-req] %s maybe down, no server is currently available" % server) raise NacosRequestException("All server are not available") self.change_server() logger.warning("[do-sync-req] %s maybe down, skip to next" % server)
Example #9
Source File: client.py From acm-sdk-python with Apache License 2.0 | 4 votes |
def _do_sync_req(self, url, headers=None, params=None, data=None, timeout=None): url = "?".join([url, urlencode(params)]) if params else url all_headers = self._get_common_headers(params, data) if headers: all_headers.update(headers) logger.debug( "[do-sync-req] url:%s, headers:%s, params:%s, data:%s, timeout:%s" % ( url, all_headers, params, data, timeout)) tries = 0 while True: try: server_info = self.get_server() if not server_info: logger.error("[do-sync-req] can not get one server.") raise ACMRequestException("Server is not available.") address, port, is_ip_address = server_info server = ":".join([address, str(port)]) # if tls is enabled and server address is in ip, turn off verification server_url = "%s://%s" % ("https" if self.tls_enabled else "http", server) req = Request(url=server_url + url, data=urlencode(data).encode() if data else None, headers=all_headers) # for python version compatibility if python_version_bellow("2.7.9"): resp = urlopen(req, timeout=timeout) else: if self.tls_enabled and is_ip_address: context = ssl.SSLContext(ssl.PROTOCOL_SSLv23) context.check_hostname = False else: context = None resp = urlopen(req, timeout=timeout, context=context) logger.debug("[do-sync-req] info from server:%s" % server) return resp except HTTPError as e: if e.code in [HTTPStatus.INTERNAL_SERVER_ERROR, HTTPStatus.BAD_GATEWAY, HTTPStatus.SERVICE_UNAVAILABLE]: logger.warning("[do-sync-req] server:%s is not available for reason:%s" % (server, e.msg)) else: raise except socket.timeout: logger.warning("[do-sync-req] %s request timeout" % server) except URLError as e: logger.warning("[do-sync-req] %s connection error:%s" % (server, e.reason)) tries += 1 if tries >= len(self.server_list): logger.error("[do-sync-req] %s maybe down, no server is currently available" % server) raise ACMRequestException("All server are not available") self.change_server() logger.warning("[do-sync-req] %s maybe down, skip to next" % server)