當前位置: 首頁>>代碼示例>>Python>>正文


Python request.get_json方法代碼示例

本文整理匯總了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 
開發者ID:gradiuscypher,項目名稱:bounty_tools,代碼行數:27,代碼來源:reconng.py

示例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") 
開發者ID:Cisco-Talos,項目名稱:BASS,代碼行數:21,代碼來源:server.py

示例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) 
開發者ID:yangmv,項目名稱:CTask,代碼行數:18,代碼來源:views.py

示例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) 
開發者ID:yangmv,項目名稱:CTask,代碼行數:18,代碼來源:views.py

示例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': {}}) 
開發者ID:kolypto,項目名稱:py-flask-jsontools,代碼行數:19,代碼來源:jsonapi-test.py

示例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 
開發者ID:simple-login,項目名稱:app,代碼行數:20,代碼來源:user_info.py

示例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) 
開發者ID:simple-login,項目名稱:app,代碼行數:24,代碼來源:auth.py

示例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 {} 
開發者ID:beavyHQ,項目名稱:beavy,代碼行數:25,代碼來源:views.py

示例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 
開發者ID:thingsboard,項目名稱:thingsboard-gateway,代碼行數:18,代碼來源:rest_connector.py

示例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") 
開發者ID:reiinakano,項目名稱:xcessiv,代碼行數:23,代碼來源:views.py

示例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) 
開發者ID:reiinakano,項目名稱:xcessiv,代碼行數:19,代碼來源:views.py

示例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) 
開發者ID:reiinakano,項目名稱:xcessiv,代碼行數:19,代碼來源:views.py

示例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) 
開發者ID:reiinakano,項目名稱:xcessiv,代碼行數:19,代碼來源:views.py

示例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) 
開發者ID:reiinakano,項目名稱:xcessiv,代碼行數:19,代碼來源:views.py

示例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 
開發者ID:deepchem,項目名稱:deepchem,代碼行數:23,代碼來源:app.py


注:本文中的flask.request.get_json方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。