本文整理汇总了Python中flask.request.get_json方法的典型用法代码示例。如果您正苦于以下问题:Python request.get_json方法的具体用法?Python request.get_json怎么用?Python request.get_json使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask.request
的用法示例。
在下文中一共展示了request.get_json方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import get_json [as 别名]
def run():
# Setup the jsonrpclib for the recon-ng RPC server, stop the API if it cannot connect to the RPC server.
try:
client = jsonrpclib.Server('http://localhost:4141')
sid = client.init()
# Get the configuration from JSON POST
content = request.get_json()
target_module = content['module']
target_domain = content['domain']
print(target_domain, target_module)
# Set the target domain
client.add('domains', target_domain, sid)
print(client.show('domains', sid))
client.use(target_module, sid)
# Execute the requested module and return the results
results = client.run(sid)
return jsonify(results)
except:
return traceback.format_exc(), 500
示例2: whitelist_add
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import get_json [as 别名]
def whitelist_add():
log.info("whitelist_add called")
try:
file_ = request.files["file"]
handle, filename = tempfile.mkstemp()
os.close(handle)
file_.save(filename)
data = request.get_json()
if data and "functions" in data:
functions = data["functions"]
else:
functions = None
bass.whitelist_add(filename, functions)
os.unlink(filename)
except KeyError:
log.exception("")
return make_response(jsonify(message = "Sample file 'file' missing in POST request"), 400)
return jsonify(message = "OK")
示例3: reomve_jobs
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import get_json [as 别名]
def reomve_jobs():
'''删除作业'''
response = {'status': '-1'}
try:
data = request.get_json(force=True)
job_id = data.get('id')
if job_id != 'all':
scheduler.remove_job(job_id)
response['msg'] = "job[%s] remove success!"%job_id
else:
scheduler.remove_all_jobs()
response['msg'] = "job all remove success!"
response['status'] = 0
except Exception as e:
response['msg'] = str(e)
return json.dumps(response)
示例4: edit_job
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import get_json [as 别名]
def edit_job():
'''修改作业'''
response = {'status': '-1'}
try:
data = request.get_json(force=True)
job_id = data.get('id')
old_job = scheduler.get_job(job_id)
if old_job:
jobfromparm(scheduler,**data)
response['status'] = 0
response['message'] = "job[%s] edit success!"%job_id
else:
response['message'] = "job[%s] Not Found!"%job_id
except Exception as e:
response['message'] = str(e)
return json.dumps(response)
示例5: testUpdate
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import get_json [as 别名]
def testUpdate(self):
""" Test PATCH /user/<id>: custom error codes, exceptions """
with self.app.test_client() as c:
# JSON error
rv = c.patch('/user/1')
self.assertEqual(rv.status_code, 403)
self.assertIsInstance(rv, JsonResponse)
self.assertEqual(rv.get_json(), {'error': 'Denied'})
# JSON user
rv = c.patch('/user/2', {'user': {'id': 2, 'name': 'bbb'}})
self.assertEqual(rv.status_code, 200)
self.assertIsInstance(rv, JsonResponse)
self.assertEqual(rv.get_json(), {'id': 2, 'name': 'bbb'})
# IndexError
self.assertRaises(IndexError, c.patch, '/user/99', {'user': {}})
示例6: create_api_key
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import get_json [as 别名]
def create_api_key():
"""Used to create a new api key
Input:
- device
Output:
- api_key
"""
data = request.get_json()
if not data:
return jsonify(error="request body cannot be empty"), 400
device = data.get("device")
api_key = ApiKey.create(user_id=g.user.id, name=device)
db.session.commit()
return jsonify(api_key=api_key.code), 201
示例7: forgot_password
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import get_json [as 别名]
def forgot_password():
"""
User forgot password
Input:
email
Output:
200 and a reset password email is sent to user
400 if email not exist
"""
data = request.get_json()
if not data or not data.get("email"):
return jsonify(error="request body must contain email"), 400
email = data.get("email").strip().lower()
user = User.get_by(email=email)
if user:
send_reset_password_email(user)
return jsonify(ok=True)
示例8: submit_story
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import get_json [as 别名]
def submit_story():
if request.method == "POST":
params = request.get_json()
title, url = params['title'].strip(), params['url'].strip()
text = params.get('text', "").strip()
if not title:
return abort(400, "You have to provide a 'title'")
if url:
link = Link(title=title, url=url, owner_id=current_user.id)
db.session.add(link)
db.session.commit()
return link_schema.dump(link)
elif text:
topic = Topic(title=title, text=text, owner_id=current_user.id)
db.session.add(topic)
db.session.commit()
return topic_schema.dump(topic)
return abort(400, "You have to provide either 'url' or 'text', too")
# Just render it
return {}
示例9: process_data
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import get_json [as 别名]
def process_data(self, request):
if not request.json:
abort(415)
endpoint_config = self.__endpoint['config']
if request.method.upper() not in [method.upper() for method in endpoint_config['HTTPMethods']]:
abort(405)
try:
log.info("CONVERTER CONFIG: %r", endpoint_config['converter'])
converter = self.__endpoint['converter'](endpoint_config['converter'])
converted_data = converter.convert(config=endpoint_config['converter'], data=request.get_json())
self.send_to_storage(self.__name, converted_data)
log.info("CONVERTED_DATA: %r", converted_data)
return "OK", 200
except Exception as e:
log.exception("Error while post to anonymous handler: %s", e)
return "", 500
示例10: create_new_ensemble
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import get_json [as 别名]
def create_new_ensemble():
req_body = request.get_json()
ensemble_name = req_body['ensemble_name']
if os.path.exists(ensemble_name):
return jsonify(message="File/folder already exists"), 400
os.makedirs(ensemble_name)
xcessiv_notebook_path = os.path.join(ensemble_name, app.config['XCESSIV_NOTEBOOK_NAME'])
sqlite_url = 'sqlite:///{}'.format(xcessiv_notebook_path)
engine = create_engine(sqlite_url)
models.Base.metadata.create_all(engine)
# Initialize
extraction = models.Extraction()
with functions.DBContextManager(ensemble_name) as session:
session.add(extraction)
session.commit()
return jsonify(message="Xcessiv notebook created")
示例11: extraction_main_dataset
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import get_json [as 别名]
def extraction_main_dataset():
path = functions.get_path_from_query_string(request)
if request.method == 'GET':
with functions.DBContextManager(path) as session:
extraction = session.query(models.Extraction).first()
return jsonify(extraction.main_dataset)
if request.method == 'PATCH':
req_body = request.get_json()
with functions.DBContextManager(path) as session:
extraction = session.query(models.Extraction).first()
for key, value in six.iteritems(req_body):
extraction.main_dataset[key] = value
session.add(extraction)
session.commit()
return jsonify(extraction.main_dataset)
示例12: extraction_test_dataset
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import get_json [as 别名]
def extraction_test_dataset():
path = functions.get_path_from_query_string(request)
if request.method == 'GET':
with functions.DBContextManager(path) as session:
extraction = session.query(models.Extraction).first()
return jsonify(extraction.test_dataset)
if request.method == 'PATCH':
req_body = request.get_json()
with functions.DBContextManager(path) as session:
extraction = session.query(models.Extraction).first()
for key, value in six.iteritems(req_body):
extraction.test_dataset[key] = value
session.add(extraction)
session.commit()
return jsonify(extraction.test_dataset)
示例13: extraction_meta_feature_generation
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import get_json [as 别名]
def extraction_meta_feature_generation():
path = functions.get_path_from_query_string(request)
if request.method == 'GET':
with functions.DBContextManager(path) as session:
extraction = session.query(models.Extraction).first()
return jsonify(extraction.meta_feature_generation)
if request.method == 'PATCH':
req_body = request.get_json()
with functions.DBContextManager(path) as session:
extraction = session.query(models.Extraction).first()
for key, value in six.iteritems(req_body):
extraction.meta_feature_generation[key] = value
session.add(extraction)
session.commit()
return jsonify(extraction.meta_feature_generation)
示例14: extraction_stacked_ensemble_cv
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import get_json [as 别名]
def extraction_stacked_ensemble_cv():
path = functions.get_path_from_query_string(request)
if request.method == 'GET':
with functions.DBContextManager(path) as session:
extraction = session.query(models.Extraction).first()
return jsonify(extraction.stacked_ensemble_cv)
if request.method == 'PATCH':
req_body = request.get_json()
with functions.DBContextManager(path) as session:
extraction = session.query(models.Extraction).first()
for key, value in six.iteritems(req_body):
extraction.stacked_ensemble_cv[key] = value
session.add(extraction)
session.commit()
return jsonify(extraction.stacked_ensemble_cv)
示例15: minimize
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import get_json [as 别名]
def minimize():
content = request.get_json(force=True)
if not content or not 'X' in content:
abort(400)
X = np.array(content['X'])
constraints = None
if 'constraints' in content:
constraints = content['constraints']
print('setting constraints')
num_atoms = X.shape[0]
x0 = X[:, 1:]
a0 = X[:, :1]
res = webapp.model.minimize_structure(x0, a0, constraints)
res = res.reshape((num_atoms, 3))
y = webapp.model.pred_one(res, a0).tolist()[0]
return flask.jsonify({'X': res.tolist(), 'y': y}), 200