本文整理汇总了Python中falcon.HTTPNotAcceptable方法的典型用法代码示例。如果您正苦于以下问题:Python falcon.HTTPNotAcceptable方法的具体用法?Python falcon.HTTPNotAcceptable怎么用?Python falcon.HTTPNotAcceptable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类falcon
的用法示例。
在下文中一共展示了falcon.HTTPNotAcceptable方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _first_hook
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTPNotAcceptable [as 别名]
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')
示例2: process_request
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTPNotAcceptable [as 别名]
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')
示例3: process_request
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTPNotAcceptable [as 别名]
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')
示例4: test_http_not_acceptable_no_title_and_desc_and_challenges
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTPNotAcceptable [as 别名]
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
示例5: test_http_not_acceptable_with_title_and_desc_and_challenges
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTPNotAcceptable [as 别名]
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
示例6: test_misc
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTPNotAcceptable [as 别名]
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)
示例7: process_request
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTPNotAcceptable [as 别名]
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')
示例8: process_request
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTPNotAcceptable [as 别名]
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.')
示例9: process_request
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTPNotAcceptable [as 别名]
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')