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


Python HTTPStatus.SERVICE_UNAVAILABLE屬性代碼示例

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


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

示例1: handle_status_code

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import SERVICE_UNAVAILABLE [as 別名]
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() 
開發者ID:bartok765,項目名稱:galaxy_blizzard_plugin,代碼行數:14,代碼來源:backend.py

示例2: handle_exception

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import SERVICE_UNAVAILABLE [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

示例3: test_http_status_to_canonical_code

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import SERVICE_UNAVAILABLE [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

示例4: test_status_codes

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import SERVICE_UNAVAILABLE [as 別名]
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() 
開發者ID:open-telemetry,項目名稱:opentelemetry-python,代碼行數:38,代碼來源:test_aiohttp_client_integration.py

示例5: handle_exception

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import SERVICE_UNAVAILABLE [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

示例6: set_http_retry_params

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import SERVICE_UNAVAILABLE [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

示例7: test_set_http_retry_params

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import SERVICE_UNAVAILABLE [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

示例8: _do_sync_req

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import SERVICE_UNAVAILABLE [as 別名]
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) 
開發者ID:nacos-group,項目名稱:nacos-sdk-python,代碼行數:52,代碼來源:client.py

示例9: _do_sync_req

# 需要導入模塊: from http import HTTPStatus [as 別名]
# 或者: from http.HTTPStatus import SERVICE_UNAVAILABLE [as 別名]
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) 
開發者ID:alibaba,項目名稱:acm-sdk-python,代碼行數:54,代碼來源:client.py


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