本文整理汇总了Python中falcon.HTTP_400属性的典型用法代码示例。如果您正苦于以下问题:Python falcon.HTTP_400属性的具体用法?Python falcon.HTTP_400怎么用?Python falcon.HTTP_400使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类falcon
的用法示例。
在下文中一共展示了falcon.HTTP_400属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: on_post
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_400 [as 别名]
def on_post(self, req, resp):
try:
json_data = self.req_json(req)
node_filter = json_data.get('node_filter', None)
design_ref = json_data.get('design_ref', None)
if design_ref is None:
self.info(req.context,
'Missing required input value: design_ref')
self.return_error(
resp,
falcon.HTTP_400,
message='Missing input required value: design_ref',
retry=False)
return
_, site_design = self.orchestrator.get_effective_site(design_ref)
nodes = self.orchestrator.process_node_filter(
node_filter=node_filter, site_design=site_design)
resp_list = [n.name for n in nodes if nodes]
resp.body = json.dumps(resp_list)
resp.status = falcon.HTTP_200
except Exception as ex:
self.error(req.context, "Unknown error: %s" % str(ex), exc_info=ex)
self.return_error(
resp, falcon.HTTP_500, message="Unknown error", retry=False)
示例2: task_validate_design
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_400 [as 别名]
def task_validate_design(self, req, resp, json_data):
"""Create async task for validate design."""
action = json_data.get('action', None)
if action != 'validate_design':
self.error(
req.context,
"Task body ended up in wrong handler: action %s in task_validate_design"
% action)
self.return_error(
resp, falcon.HTTP_500, message="Error", retry=False)
try:
task = self.create_task(json_data, req.context)
resp.body = json.dumps(task.to_dict())
resp.append_header('Location',
"/api/v1.0/tasks/%s" % str(task.task_id))
resp.status = falcon.HTTP_201
except errors.InvalidFormat as ex:
self.error(req.context, ex.msg)
self.return_error(
resp, falcon.HTTP_400, message=ex.msg, retry=False)
示例3: task_prepare_site
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_400 [as 别名]
def task_prepare_site(self, req, resp, json_data):
"""Create async task for prepare site."""
action = json_data.get('action', None)
if action != 'prepare_site':
self.error(
req.context,
"Task body ended up in wrong handler: action %s in task_prepare_site"
% action)
self.return_error(
resp, falcon.HTTP_500, message="Error", retry=False)
try:
task = self.create_task(json_data, req.context)
resp.body = json.dumps(task.to_dict())
resp.append_header('Location',
"/api/v1.0/tasks/%s" % str(task.task_id))
resp.status = falcon.HTTP_201
except errors.InvalidFormat as ex:
self.error(req.context, ex.msg)
self.return_error(
resp, falcon.HTTP_400, message=ex.msg, retry=False)
示例4: task_verify_nodes
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_400 [as 别名]
def task_verify_nodes(self, req, resp, json_data):
"""Create async task for verify node."""
action = json_data.get('action', None)
if action != 'verify_nodes':
self.error(
req.context,
"Task body ended up in wrong handler: action %s in task_verify_nodes"
% action)
self.return_error(
resp, falcon.HTTP_500, message="Error", retry=False)
try:
task = self.create_task(json_data, req.context)
resp.body = json.dumps(task.to_dict())
resp.append_header('Location',
"/api/v1.0/tasks/%s" % str(task.task_id))
resp.status = falcon.HTTP_201
except errors.InvalidFormat as ex:
self.error(req.context, ex.msg)
self.return_error(
resp, falcon.HTTP_400, message=ex.msg, retry=False)
示例5: task_prepare_nodes
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_400 [as 别名]
def task_prepare_nodes(self, req, resp, json_data):
"""Create async task for prepare node."""
action = json_data.get('action', None)
if action != 'prepare_nodes':
self.error(
req.context,
"Task body ended up in wrong handler: action %s in task_prepare_nodes"
% action)
self.return_error(
resp, falcon.HTTP_500, message="Error", retry=False)
try:
task = self.create_task(json_data, req.context)
resp.body = json.dumps(task.to_dict())
resp.append_header('Location',
"/api/v1.0/tasks/%s" % str(task.task_id))
resp.status = falcon.HTTP_201
except errors.InvalidFormat as ex:
self.error(req.context, ex.msg)
self.return_error(
resp, falcon.HTTP_400, message=ex.msg, retry=False)
示例6: task_deploy_nodes
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_400 [as 别名]
def task_deploy_nodes(self, req, resp, json_data):
"""Create async task for deploy node."""
action = json_data.get('action', None)
if action != 'deploy_nodes':
self.error(
req.context,
"Task body ended up in wrong handler: action %s in task_deploy_nodes"
% action)
self.return_error(
resp, falcon.HTTP_500, message="Error", retry=False)
try:
task = self.create_task(json_data, req.context)
resp.body = json.dumps(task.to_dict())
resp.append_header('Location',
"/api/v1.0/tasks/%s" % str(task.task_id))
resp.status = falcon.HTTP_201
except errors.InvalidFormat as ex:
self.error(req.context, ex.msg)
self.return_error(
resp, falcon.HTTP_400, message=ex.msg, retry=False)
示例7: task_destroy_nodes
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_400 [as 别名]
def task_destroy_nodes(self, req, resp, json_data):
"""Create async task for destroy node."""
action = json_data.get('action', None)
if action != 'destroy_nodes':
self.error(
req.context,
"Task body ended up in wrong handler: action %s in task_destroy_nodes"
% action)
self.return_error(
resp, falcon.HTTP_500, message="Error", retry=False)
try:
task = self.create_task(json_data, req.context)
resp.body = json.dumps(task.to_dict())
resp.append_header('Location',
"/api/v1.0/tasks/%s" % str(task.task_id))
resp.status = falcon.HTTP_201
except errors.InvalidFormat as ex:
self.error(req.context, ex.msg)
self.return_error(
resp, falcon.HTTP_400, message=ex.msg, retry=False)
示例8: recordUser
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_400 [as 别名]
def recordUser(session, valueDict):
userRow = None
requiredValues = ["Signature", "Name", "Email", "UserID"]
for value in requiredValues:
if value not in valueDict.keys():
return None
#resp.body = "Error, missing key {}".format(value)
#resp.status = falcon.HTTP_400
# User table values
signature = valueDict.get("Signature")
name = valueDict.get("Name")
email = valueDict.get("Email")
company = valueDict.get("Company")
userID = valueDict.get("UserID")
userExists = True
userRow = session.query(UsersTable).get((signature, userID))
if userRow is None:
userExists = False
userRow = UsersTable(Signature=signature, Name=name, Email=email, Company=company, UserID=userID, InstallDateTime=ctime())
return userRow, userExists
示例9: on_post
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_400 [as 别名]
def on_post(self, req, resp):
try:
json_data = self.req_json(req)
node_filter = json_data.get('node_filter', None)
design_ref = json_data.get('design_ref', None)
if design_ref is None:
self.info(req.context, 'Missing required input value: design_ref')
self.return_error(
resp,
falcon.HTTP_400,
message='Missing input required value: design_ref',
retry=False)
return
_, site_design = self.orchestrator.get_effective_site(design_ref)
nodes = self.orchestrator.process_node_filter(node_filter=node_filter,
site_design=site_design)
resp_list = [n.name for n in nodes if nodes]
resp.body = json.dumps(resp_list)
resp.status = falcon.HTTP_200
except Exception as ex:
self.error(req.context, "Unknown error: %s" % str(ex), exc_info=ex)
self.return_error(
resp, falcon.HTTP_500, message="Unknown error", retry=False)
示例10: add_messages_to_validation_status
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_400 [as 别名]
def add_messages_to_validation_status(status, msgs, level):
"""Given a status retrieved from _format_validations_to_status and a list
of messages at a given level (Error, Warning, Info), add messages to the
status
"""
code = falcon.HTTP_200
if str(level).lower() == 'error':
code = falcon.HTTP_400
status['status'] = 'Failure'
status['message'] = 'Validations failed'
status['code'] = code
status['details']['errorCount'] += len(msgs)
formatted_messages = []
for msg in msgs:
formatted_messages.append({'code': code,
'message': msg,
'status': str(level).capitalize(),
'level': str(level).lower()})
status['details']['messageList'] += formatted_messages
示例11: _format_validations_to_status
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_400 [as 别名]
def _format_validations_to_status(val_msgs, error_count):
"""Using a list of validation messages and an error count,
formulates and returns a status response dict
"""
status = 'Success'
message = 'Validations succeeded'
code = falcon.HTTP_200
if error_count > 0:
status = 'Failure'
message = 'Validations failed'
code = falcon.HTTP_400
return {
"kind": "Status",
"apiVersion": "v1.0",
"metadata": {},
"status": status,
"message": message,
"reason": "Validation",
"details": {
"errorCount": error_count,
"messageList": val_msgs,
},
"code": code
}
示例12: verbosity
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_400 [as 别名]
def verbosity(self, req):
"""Process the verbosity parameter
:param req: the Falcon request object
Valid values range from 0 (none) to 5 (maximum verbosity)
"""
try:
verbosity = req.get_param_as_int(
'verbosity', required=False, min=0, max=MAX_VERBOSITY
)
if verbosity is not None:
# if not set, retains the context default value.
req.context.verbosity = verbosity
except falcon.HTTPBadRequest as hbr:
LOG.exception(hbr)
raise ApiError(
title="Invalid verbosity parameter",
description=("If specified, verbosity parameter should be a "
"value from 0 to {}".format(MAX_VERBOSITY)),
status=falcon.HTTP_400
)
示例13: validate_content_length
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_400 [as 别名]
def validate_content_length(self, content_length):
"""Validates that the content length header is valid
:param content_length: the value of the content-length header.
:returns: the validate content length value
"""
content_length = content_length or 0
if (content_length == 0):
raise ApiError(
title=('Content-Length is a required header'),
description='Content Length is 0 or not specified',
status=falcon.HTTP_400,
error_list=[{
'message': (
"The Content-Length specified is 0 or not set. To "
"clear a collection's contents, please specify "
"the query parameter 'empty-collection=true'."
"Otherwise, a non-zero length payload and "
"matching Content-Length header is required to "
"post a collection.")
}],
retry=False, )
return content_length
示例14: on_post
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_400 [as 别名]
def on_post(self, req, resp):
"""Method handler for POST requests.
:param req: Falcon request object
:param resp: Falcon response object
"""
try:
json_data = self.req_json(req)
design = None
if json_data is not None:
base_design = json_data.get('base_design_id', None)
if base_design is not None:
base_design = uuid.UUID(base_design)
design = hd_objects.SiteDesign(base_design_id=base_design)
else:
design = hd_objects.SiteDesign()
design.assign_id()
design.create(req.context, self.state_manager)
resp.body = json.dumps(design.obj_to_simple())
resp.status = falcon.HTTP_201
except errors.StateError:
self.error(req.context, "Error updating persistence")
self.return_error(
resp,
falcon.HTTP_500,
message="Error updating persistence",
retry=True)
except errors.InvalidFormat as fex:
self.error(req.context, str(fex))
self.return_error(
resp, falcon.HTTP_400, message=str(fex), retry=False)
示例15: on_post
# 需要导入模块: import falcon [as 别名]
# 或者: from falcon import HTTP_400 [as 别名]
def on_post(self, req, resp):
"""Handler for POST method."""
# A map of supported actions to the handlers for tasks for those actions
supported_actions = {
'validate_design': TasksResource.task_validate_design,
'verify_site': TasksResource.task_verify_site,
'prepare_site': TasksResource.task_prepare_site,
'verify_nodes': TasksResource.task_verify_nodes,
'prepare_nodes': TasksResource.task_prepare_nodes,
'deploy_nodes': TasksResource.task_deploy_nodes,
'destroy_nodes': TasksResource.task_destroy_nodes,
'relabel_nodes': TasksResource.task_relabel_nodes,
}
try:
json_data = self.req_json(req)
action = json_data.get('action', None)
if supported_actions.get(action, None) is None:
self.error(req.context, "Unsupported action %s" % action)
self.return_error(
resp,
falcon.HTTP_400,
message="Unsupported action %s" % action,
retry=False)
else:
supported_actions.get(action)(self, req, resp, json_data)
except Exception as ex:
self.error(
req.context,
"Unknown error: %s\n%s" % (str(ex), traceback.format_exc()))
self.return_error(
resp, falcon.HTTP_500, message="Unknown error", retry=False)