Python falcon 模块,HTTPNotAcceptable() 实例源码

我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用falcon.HTTPNotAcceptable()

项目:CAL    作者:HPCC-Cloud-Computing    | 项目源码 | 文件源码
def _first_hook(req, resp, resource, params):
    if resource.req_ids is None:
        raise falcon.HTTPBadRequest(title='Append request id failed',
                                    description='Append request id failed')

    if((req.env['calplus.cloud'] != 'cloud1') or
        ('request-id' not in req.env)):
        raise falcon.HTTPBadRequest(title='Process Request Error',
                                    description='Problem when process request')

    if not req.client_accepts_json:
        raise falcon.HTTPNotAcceptable(
            'This API only supports responses encoded as JSON.',
            href='http://docs.examples.com/api/json')

    if req.method in ('POST', 'PUT'):
        if 'application/json' not in req.content_type:
            raise falcon.HTTPUnsupportedMediaType(
                'This API only supports requests encoded as JSON.',
                href='http://docs.examples.com/api/json')
项目:falcon-api    作者:Opentopic    | 项目源码 | 文件源码
def process_request(self, req, resp):
        """
        :param req: Falcon request
        :type req: falcon.request.Request
        :param resp: Falcon response
        :type resp: falcon.response.Response
        """
        if not req.client_accepts_json:
            raise falcon.HTTPNotAcceptable(
                'This API only supports responses encoded as JSON.',
                href='http://docs.examples.com/api/json')

        if req.method in ('POST', 'PUT', 'PATCH'):
            if req.content_type is None or 'application/json' not in req.content_type:
                raise falcon.HTTPUnsupportedMediaType(
                    'This API only supports requests encoded as JSON.',
                    href='http://docs.examples.com/api/json')
项目:deb-python-falcon    作者:openstack    | 项目源码 | 文件源码
def process_request(self, req, resp):
        if not req.client_accepts_json:
            raise falcon.HTTPNotAcceptable(
                'This API only supports responses encoded as JSON.',
                href='http://docs.examples.com/api/json')

        if req.method in ('POST', 'PUT'):
            if 'application/json' not in req.content_type:
                raise falcon.HTTPUnsupportedMediaType(
                    'This API only supports requests encoded as JSON.',
                    href='http://docs.examples.com/api/json')
项目:deb-python-falcon    作者:openstack    | 项目源码 | 文件源码
def test_http_not_acceptable_no_title_and_desc_and_challenges():
    try:
        raise falcon.HTTPNotAcceptable()
    except falcon.HTTPNotAcceptable as e:
        assert e.description is None
项目:deb-python-falcon    作者:openstack    | 项目源码 | 文件源码
def test_http_not_acceptable_with_title_and_desc_and_challenges():
    try:
        raise falcon.HTTPNotAcceptable(description='Testdescription')
    except falcon.HTTPNotAcceptable as e:
        assert 'Testdescription' == e.description
项目:deb-python-falcon    作者:openstack    | 项目源码 | 文件源码
def test_misc(self, client):
        self._misc_test(client, falcon.HTTPBadRequest, falcon.HTTP_400)
        self._misc_test(client, falcon.HTTPNotAcceptable, falcon.HTTP_406,
                        needs_title=False)
        self._misc_test(client, falcon.HTTPConflict, falcon.HTTP_409)
        self._misc_test(client, falcon.HTTPPreconditionFailed, falcon.HTTP_412)
        self._misc_test(client, falcon.HTTPUnsupportedMediaType, falcon.HTTP_415,
                        needs_title=False)
        self._misc_test(client, falcon.HTTPUnprocessableEntity, falcon.HTTP_422)
        self._misc_test(client, falcon.HTTPUnavailableForLegalReasons, falcon.HTTP_451,
                        needs_title=False)
        self._misc_test(client, falcon.HTTPInternalServerError, falcon.HTTP_500)
        self._misc_test(client, falcon.HTTPBadGateway, falcon.HTTP_502)
项目:orbital-cotwo-web    作者:chronos-pramantha    | 项目源码 | 文件源码
def process_request(self, req, resp):
        if not req.client_accepts_json:
            raise falcon.HTTPNotAcceptable(
                'This API only supports requests encoded as JSON.',
                href='http://docs.examples.com/api/json')

        if req.method in ('POST', 'PUT'):
            if 'application/json' not in req.content_type:
                raise falcon.HTTPUnsupportedMediaType(
                    'This API only supports requests encoded as JSON.',
                    href='http://docs.examples.com/api/json')
项目:EVA    作者:metno    | 项目源码 | 文件源码
def process_request(self, req, resp):
        if not req.client_accepts_json:
            raise falcon.HTTPNotAcceptable('This API only supports responses encoded as JSON.')

        if req.method in ('POST', 'PUT') and req.content_length not in (None, 0):
            if 'application/json' not in req.content_type:
                raise falcon.HTTPUnsupportedMediaType('This API only supports requests encoded as JSON.')
项目:metricsandstuff    作者:bucknerns    | 项目源码 | 文件源码
def process_request(self, req, resp):

        if not req.client_accepts_json:
            raise falcon.HTTPNotAcceptable(
                'This API only supports responses encoded as JSON.',
                href='http://docs.examples.com/api/json')

        if req.method in ('POST', 'PUT'):
            if 'application/json' not in req.content_type:
                raise falcon.HTTPUnsupportedMediaType(
                    'This API only supports requests encoded as JSON.',
                    href='http://docs.examples.com/api/json')