本文整理汇总了Python中falcon.http_error.HTTPError.__init__方法的典型用法代码示例。如果您正苦于以下问题:Python HTTPError.__init__方法的具体用法?Python HTTPError.__init__怎么用?Python HTTPError.__init__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类falcon.http_error.HTTPError
的用法示例。
在下文中一共展示了HTTPError.__init__方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from falcon.http_error import HTTPError [as 别名]
# 或者: from falcon.http_error.HTTPError import __init__ [as 别名]
def __init__(self, title, description, retry_after, **kwargs):
"""Initialize
Args:
title: Human-friendly error title. Set to None if you wish Falcon
to return an empty response body (all remaining args will
be ignored except for headers.) Do this only when you don't
wish to disclose sensitive information about why a request was
refused, or if the status and headers are self-descriptive.
description: Human-friendly description of the error, along with a
helpful suggestion or two (default None).
retry_after: Value for the Retry-After header. If a date object,
will serialize as an HTTP date. Otherwise, a non-negative int
is expected, representing the number of seconds to wait. See
also: http://goo.gl/DIrWr
headers: A dictionary of extra headers to return in the
response to the client (default None).
href: A URL someone can visit to find out more information
(default None).
href_rel: If href is given, use this value for the rel
attribute (default 'doc').
href_text: If href is given, use this as the friendly
title/description for the link (defaults to "API documentation
for this error").
code: An internal code that customers can reference in their
support request or to help them when searching for knowledge
base articles related to this error.
"""
headers = kwargs.setdefault('headers', {})
headers['Retry-After'] = str(retry_after)
HTTPError.__init__(self, status.HTTP_503, title, description, **kwargs)
示例2: __init__
# 需要导入模块: from falcon.http_error import HTTPError [as 别名]
# 或者: from falcon.http_error.HTTPError import __init__ [as 别名]
def __init__(self, title, description, retry_after, **kwargs):
"""Initialize
"""
headers = kwargs.setdefault('headers', {})
headers['Retry-After'] = str(retry_after)
HTTPError.__init__(self, status.HTTP_503, title, description, **kwargs)
示例3: __init__
# 需要导入模块: from falcon.http_error import HTTPError [as 别名]
# 或者: from falcon.http_error.HTTPError import __init__ [as 别名]
def __init__(self, title, description, **kwargs):
headers = kwargs.setdefault('headers', {})
scheme = kwargs.pop('scheme', None)
if scheme is not None:
headers['WWW-Authenticate'] = scheme
HTTPError.__init__(self, status.HTTP_401, title, description, **kwargs)
示例4: __init__
# 需要导入模块: from falcon.http_error import HTTPError [as 别名]
# 或者: from falcon.http_error.HTTPError import __init__ [as 别名]
def __init__(self, allowed_methods, **kwargs):
HTTPError.__init__(self, status.HTTP_405, 'Method not allowed',
**kwargs)
if kwargs:
title = 'Method not allowed'
else:
# NOTE(kgriffs): Trigger an empty body in the response; 405
# responses don't usually have bodies, so we only send one
# if the caller indicates they want one, by way of specifying
# a description, href, and/or other details.
title = None
# NOTE(kgriffs): Inject the "Allow" header so it will be included
# in the HTTP response.
headers = kwargs.setdefault('headers', {})
headers['Allow'] = ', '.join(allowed_methods)
HTTPError.__init__(self, status.HTTP_405, title, **kwargs)
示例5: __init__
# 需要导入模块: from falcon.http_error import HTTPError [as 别名]
# 或者: from falcon.http_error.HTTPError import __init__ [as 别名]
def __init__(self, allowed_methods, **kwargs):
HTTPError.__init__(self, status.HTTP_405, 'Method not allowed',
**kwargs)
# NOTE(kgriffs): Trigger an empty body in the response; 405
# responses don't usually have bodies, so we only send one
# if the caller indicates they want one by providing some
# details in the kwargs.
if kwargs:
title = 'Method not allowed'
self._has_representation = True
else:
title = None
self._has_representation = False
# NOTE(kgriffs): Inject the "Allow" header so it will be included
# in the HTTP response.
headers = kwargs.setdefault('headers', {})
headers['Allow'] = ', '.join(allowed_methods)
HTTPError.__init__(self, status.HTTP_405, title=title, **kwargs)
示例6: __init__
# 需要导入模块: from falcon.http_error import HTTPError [as 别名]
# 或者: from falcon.http_error.HTTPError import __init__ [as 别名]
def __init__(self, title, description, **kwargs):
HTTPError.__init__(self, HTTP_400, title, description, **kwargs)
示例7: __init__
# 需要导入模块: from falcon.http_error import HTTPError [as 别名]
# 或者: from falcon.http_error.HTTPError import __init__ [as 别名]
def __init__(self, description, **kwargs):
HTTPError.__init__(self, status.HTTP_415, "Unsupported Media Type", description, **kwargs)
示例8: __init__
# 需要导入模块: from falcon.http_error import HTTPError [as 别名]
# 或者: from falcon.http_error.HTTPError import __init__ [as 别名]
def __init__(self, title, description, **kwargs):
HTTPError.__init__(self, '422 Unprocessable Entity', title, description, **kwargs)