本文整理汇总了Python中werkzeug.exceptions.HTTPException类的典型用法代码示例。如果您正苦于以下问题:Python HTTPException类的具体用法?Python HTTPException怎么用?Python HTTPException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HTTPException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, data, description=None):
"""
param: data: A dictionary containing the field errors that occured
param: description: Optional description to send through
"""
HTTPException.__init__(self)
self.data = data
示例2: handle_error
def handle_error(self, e):
if e.__class__ in self._error_handlers:
handler = self._error_handlers[e.__class__]
result = handler(e)
e = HTTPException(str(e))
e.data, e.code = result if len(result) == 2 else (result, 500)
return super(Api, self).handle_error(e)
示例3: __init__
def __init__(self, description, locator="", code=400):
self.code = code
self.description = description
self.locator = locator
logging.exception(description)
HTTPException.__init__(self)
示例4: __init__
def __init__(self, description, locator="", code=400):
self.code = code
self.description = description
self.locator = locator
msg = 'Exception: code: %s, locator: %s, description: %s' % (self.code, self.description, self.locator)
LOGGER.exception(msg)
HTTPException.__init__(self)
示例5: test_handle_error_401_sends_challege_default_realm
def test_handle_error_401_sends_challege_default_realm(self, api):
exception = HTTPException()
exception.code = 401
exception.data = {'foo': 'bar'}
resp = api.handle_error(exception)
assert resp.status_code == 401
assert resp.headers['WWW-Authenticate'] == 'Basic realm="flask-restplus"'
示例6: abort
def abort(response, status_code=None):
if isinstance(response, basestring):
response = make_response(response)
if status_code:
response.status_code = status_code
e = HTTPException(response=response)
e.code = getattr(response, 'status_code', 0)
raise e
示例7: __init__
def __init__(message=None, data=None, code=400, **kwargs):
data = data or kwargs
if instanceof(message, str):
data, message = message, None
if message:
data["message"] = message
response = jsonify(status="fail", data=data)
response.status_code = status_code
HTTPException.__init__(self, message, response)
self.code = code
示例8: test_handle_error_401_sends_challege_default_realm
def test_handle_error_401_sends_challege_default_realm(self):
api = restplus.Api(self.app, serve_challenge_on_401=True)
exception = HTTPException()
exception.code = 401
exception.data = {'foo': 'bar'}
with self.app.test_request_context('/foo'):
resp = api.handle_error(exception)
self.assertEqual(resp.status_code, 401)
self.assertEqual(resp.headers['WWW-Authenticate'],
'Basic realm="flask-restful"')
示例9: create_app
def create_app(settings_override=None, register_security_blueprint=False):
app = factory.create_app(__name__, __path__, settings_override, register_security_blueprint)
# Init API endpoints for models
api_manager.init_app(app)
# Setup security async email send
security_ctx = app.extensions['security']
@security_ctx.send_mail_task
def delay_security_email(msg): # pylint: disable=unused-variable
tasks.send_security_email.delay(msg)
# Register custom error handlers so they all return JSON
if not app.debug:
for http_exception_class in HTTPException.__subclasses__():
app.errorhandler(http_exception_class.code)(handle_error)
return app
示例10: init
def init(self, description=None, response=None, traceback=None):
self.traceback = traceback
HTTPException.__init__(self, description, response)
示例11: __init__
def __init__(self, article_name, original_link, description=None):
HTTPException.__init__(self, description)
self.article_name = article_name
self.original_link = original_link
示例12: get_headers
def get_headers(self, environ):
headers = HTTPException.get_headers(self, environ)
headers.append(('WWW-Authenticate', 'Basic realm="MCM API"'))
return headers
示例13: __init__
def __init__(self, code, description):
HTTPException.__init__(self)
self.code = code
self.description = description
示例14: __init__
def __init__(self, location):
HTTPException.__init__(self)
self.location = location
示例15: http_ensure
def http_ensure(case, msg, code=400):
"if not case, raise a client error exception (by default)"
if not case:
ex = HTTPException(msg)
ex.code = code
raise ex