python类HTTPNotAcceptable()的实例源码

test_wsgi.py 文件源码 项目:CAL 作者: HPCC-Cloud-Computing 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
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')
json_middleware.py 文件源码 项目:falcon-api 作者: Opentopic 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
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')
test_example.py 文件源码 项目:deb-python-falcon 作者: openstack 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
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')
test_error.py 文件源码 项目:deb-python-falcon 作者: openstack 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
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
test_error.py 文件源码 项目:deb-python-falcon 作者: openstack 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
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
test_httperror.py 文件源码 项目:deb-python-falcon 作者: openstack 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
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)
webserver.py 文件源码 项目:orbital-cotwo-web 作者: chronos-pramantha 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
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')
__init__.py 文件源码 项目:EVA 作者: metno 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
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.')
run.py 文件源码 项目:metricsandstuff 作者: bucknerns 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
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')


问题


面经


文章

微信
公众号

扫码关注公众号