当前位置: 首页>>代码示例>>Python>>正文


Python request.get_data方法代码示例

本文整理汇总了Python中flask.request.get_data方法的典型用法代码示例。如果您正苦于以下问题:Python request.get_data方法的具体用法?Python request.get_data怎么用?Python request.get_data使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在flask.request的用法示例。


在下文中一共展示了request.get_data方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: do_POST

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import get_data [as 别名]
def do_POST(self, service=""):
        log.debug("NebHookServer: Plugin=%s : Incoming request from %s",
                  service, request.remote_addr)
        if service.split("/")[0] not in self.plugin_mappings:
            return ("", 404, {})

        plugin = self.plugin_mappings[service.split("/")[0]]

        try:
            # tuple (body, status_code, headers)
            response = plugin.on_receive_webhook(
                request.url,
                request.get_data(),
                request.remote_addr,
                request.headers
            )
            if response:
                return response
            return ("", 200, {})
        except Exception as e:
            log.exception(e)
            return ("", 500, {}) 
开发者ID:matrix-org,项目名称:Matrix-NEB,代码行数:24,代码来源:webhook.py

示例2: predict_image_handler

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import get_data [as 别名]
def predict_image_handler():
    try:
        imageData = None
        if ('imageData' in request.files):
            imageData = request.files['imageData']
        else:
            imageData = io.BytesIO(request.get_data())

        #img = scipy.misc.imread(imageData)
        img = Image.open(imageData)
        results = predict_image(img)
        return json.dumps(results)
    except Exception as e:
        print('EXCEPTION:', str(e))
        return 'Error processing image', 500


# Like the CustomVision.ai Prediction service /url route handles url's
# in the body of hte request of the form:
#     { 'Url': '<http url>'} 
开发者ID:jamesbannan,项目名称:pluralsight,代码行数:22,代码来源:app.py

示例3: predict_image_handler

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import get_data [as 别名]
def predict_image_handler(project=None, publishedName=None):
    try:
        imageData = None
        if ('imageData' in request.files):
            imageData = request.files['imageData']
        elif ('imageData' in request.form):
            imageData = request.form['imageData']
        else:
            imageData = io.BytesIO(request.get_data())

        img = Image.open(imageData)
        results = predict_image(img)
        return jsonify(results)
    except Exception as e:
        print('EXCEPTION:', str(e))
        return 'Error processing image', 500


# Like the CustomVision.ai Prediction service /url route handles url's
# in the body of hte request of the form:
#     { 'Url': '<http url>'} 
开发者ID:Azure-Samples,项目名称:Custom-vision-service-iot-edge-raspberry-pi,代码行数:23,代码来源:app.py

示例4: slack_app

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import get_data [as 别名]
def slack_app():
    if not signature_verifier.is_valid_request(request.get_data(), request.headers):
        return make_response("invalid request", 403)

    if "command" in request.form \
        and request.form["command"] == "/view":
        trigger_id = request.form["trigger_id"]
        return open_modal(trigger_id)

    elif "payload" in request.form:
        payload = json.loads(request.form["payload"])
        if payload["type"] == "view_submission" \
            and payload["view"]["callback_id"] == "modal-id":
            submitted_data = payload["view"]["state"]["values"]
            print(submitted_data)  # {'b-id': {'a-id': {'type': 'plain_text_input', 'value': 'your input'}}}
            return make_response("", 200)
        if payload["type"] == "shortcut" \
            and payload["callback_id"] == "view-test":
            return open_modal(payload["trigger_id"])

    return make_response("", 404) 
开发者ID:slackapi,项目名称:python-slackclient,代码行数:23,代码来源:views_default_to_current_conversation.py

示例5: post

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import get_data [as 别名]
def post(self):
        parameters = json.loads(request.get_data(as_text=True))

        partial_element = parameters['partial_element']

        if len(partial_element) < 2:
            return flask.jsonify({'success': True, 'result': []})

        try:
            interactions = cellphonedb_app.cellphonedb.query.autocomplete_launcher(partial_element)
            response = {
                'success': True,
                'result': interactions.to_dict(orient='records')
            }
        except:
            response = {
                'success': False
            }
            print(traceback.print_exc(file=sys.stdout))

        return flask.jsonify(response) 
开发者ID:Teichlab,项目名称:cellphonedb,代码行数:23,代码来源:web_endpoint_query_autocomplete.py

示例6: post

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import get_data [as 别名]
def post(self):
        parameters = json.loads(request.get_data(as_text=True))

        complex_name = parameters['complex_name']

        deconvoluted = cellphonedb_app.cellphonedb.query.get_complex_deconvoluted(complex_name)

        if deconvoluted.empty:
            self.attach_error(
                {'code': 'element_not_found', 'title': '%s is not CellPhoneDB Complex' % complex_name,
                 'details': '%s is not present in CellPhoneDB complex table' % complex_name})
        else:
            self._attach_csv(deconvoluted.to_csv(index=False, sep=','), 'result')

        self._commit_attachments()

        return Response(self._msg.as_string(), mimetype='multipart/form-data; boundary="%s"' % self._msg.get_boundary()) 
开发者ID:Teichlab,项目名称:cellphonedb,代码行数:19,代码来源:web_endpoint_query_complex_deconvoluted.py

示例7: post

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import get_data [as 别名]
def post(self):
        parameters = json.loads(request.get_data(as_text=True))

        receptor = parameters['receptor']

        interactions = cellphonedb_app.cellphonedb.query.find_interactions_by_element(receptor)

        if interactions.empty:
            self.attach_error(
                {'code': 'result_not_found', 'title': '%s is not CellPhoneDB interactor' % receptor,
                 'details': '%s is not present in CellPhoneDB interactor enabled table' % receptor})
        else:
            self._attach_csv(interactions.to_csv(index=False, sep=','), 'ligands')

        self._commit_attachments()

        return Response(self._msg.as_string(), mimetype='multipart/form-data; boundary="%s"' % self._msg.get_boundary()) 
开发者ID:Teichlab,项目名称:cellphonedb,代码行数:19,代码来源:web_endpoint_query_find_interactions_by_element.py

示例8: post

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import get_data [as 别名]
def post(self):
        id = request.get_data('id')
        project = id.decode('utf-8')
        if not project:
            return jsonify({'msg': u'没有发送数据', 'code': 38, 'data': ''})
        project_is = Project.query.filter_by(project_name=project).first()
        if not project_is:
            return jsonify(({'msg': u'成功', 'code': 200, 'data': []}))
        testreport = TestResult.query.filter_by(projects_id=project_is.id, status=False).order_by('-id').all()
        testreportlist = []
        for test in testreport:
            testreportlist.append({'test_num': test.test_num, 'pass_num': test.pass_num,
                                   'fail_num': test.fail_num, 'hour_time': str(test.hour_time),
                                   'test_rep': test.test_rep, 'test_log': test.test_log,
                                   'Exception_num': test.Exception_num, 'can_num': test.can_num,
                                   'wei_num': test.wei_num, 'test_time': str(test.test_time),
                                   'Test_user_id': test.users.username, 'id': test.id,
                                   'fenshu': test.pass_num / test.test_num})
        return jsonify(({'msg': u'成功', 'code': 200, 'data': (testreportlist)})) 
开发者ID:liwanlei,项目名称:FXTest,代码行数:21,代码来源:views.py

示例9: test_flask_large_json_request

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import get_data [as 别名]
def test_flask_large_json_request(sentry_init, capture_events, app):
    sentry_init(integrations=[flask_sentry.FlaskIntegration()])

    data = {"foo": {"bar": "a" * 2000}}

    @app.route("/", methods=["POST"])
    def index():
        assert request.get_json() == data
        assert request.get_data() == json.dumps(data).encode("ascii")
        assert not request.form
        capture_message("hi")
        return "ok"

    events = capture_events()

    client = app.test_client()
    response = client.post("/", content_type="application/json", data=json.dumps(data))
    assert response.status_code == 200

    (event,) = events
    assert event["_meta"]["request"]["data"]["foo"]["bar"] == {
        "": {"len": 2000, "rem": [["!limit", "x", 509, 512]]}
    }
    assert len(event["request"]["data"]["foo"]["bar"]) == 512 
开发者ID:getsentry,项目名称:sentry-python,代码行数:26,代码来源:test_flask.py

示例10: test_flask_empty_json_request

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import get_data [as 别名]
def test_flask_empty_json_request(sentry_init, capture_events, app, data):
    sentry_init(integrations=[flask_sentry.FlaskIntegration()])

    @app.route("/", methods=["POST"])
    def index():
        assert request.get_json() == data
        assert request.get_data() == json.dumps(data).encode("ascii")
        assert not request.form
        capture_message("hi")
        return "ok"

    events = capture_events()

    client = app.test_client()
    response = client.post("/", content_type="application/json", data=json.dumps(data))
    assert response.status_code == 200

    (event,) = events
    assert event["request"]["data"] == data 
开发者ID:getsentry,项目名称:sentry-python,代码行数:21,代码来源:test_flask.py

示例11: test_flask_medium_formdata_request

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import get_data [as 别名]
def test_flask_medium_formdata_request(sentry_init, capture_events, app):
    sentry_init(integrations=[flask_sentry.FlaskIntegration()])

    data = {"foo": "a" * 2000}

    @app.route("/", methods=["POST"])
    def index():
        assert request.form["foo"] == data["foo"]
        assert not request.get_data()
        assert not request.get_json()
        capture_message("hi")
        return "ok"

    events = capture_events()

    client = app.test_client()
    response = client.post("/", data=data)
    assert response.status_code == 200

    (event,) = events
    assert event["_meta"]["request"]["data"]["foo"] == {
        "": {"len": 2000, "rem": [["!limit", "x", 509, 512]]}
    }
    assert len(event["request"]["data"]["foo"]) == 512 
开发者ID:getsentry,项目名称:sentry-python,代码行数:26,代码来源:test_flask.py

示例12: rename_path_on_json

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import get_data [as 别名]
def rename_path_on_json():
    req_data = json.loads(request.get_data() or '{}')
    file_objs = req_data['file_objs']
    path = req_data['path']

    # handle usual error
    if not os.path.exists(path):
        return jsonify({'response': [{'file_name': f'{path} does not exist'}]}), 400
    if not os.path.isdir(path):
        return jsonify({'response': [{'file_name': f'{path} is not a valid directory for scan'}]}), 400

    def long_process():
        for each_file_process in EmbyFileStructure.rename_directory(path, file_objs):
            yield json.dumps({'log': each_file_process})+'\n'

    return Response(long_process(), mimetype='text/event-stream') 
开发者ID:ddd354,项目名称:JAVOneStop,代码行数:18,代码来源:scan_directory.py

示例13: update_db_jav

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import get_data [as 别名]
def update_db_jav():
    req_data = json.loads(request.get_data() or '{}')
    jav_pk = req_data.get('pk')
    update_data = req_data.get('data')

    if not jav_pk:
        return jsonify({'error': 'no pk found in posted json'}), 400

    db_conn = JavManagerDB()
    try:
        current_jav_obj = dict(db_conn.get_by_pk(jav_pk))
    except DoesNotExist:
        current_jav_obj = {'car': jav_pk}

    current_jav_obj.update(update_data)
    db_conn.upcreate_jav(current_jav_obj)

    return jsonify({'success': dict(current_jav_obj)}) 
开发者ID:ddd354,项目名称:JAVOneStop,代码行数:20,代码来源:javlib_browser.py

示例14: update_jav_dict

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import get_data [as 别名]
def update_jav_dict():
    # update db jav dict, also rewrite nfo and images

    req_data = json.loads(request.get_data() or '{}')
    update_dict = req_data['update_dict']

    # update db
    db_conn = JavManagerDB()
    db_conn.upcreate_jav(update_dict)

    file_writer = EmbyFileStructure(return_default_config_string('file_path'))
     # file structure operations
    try:
        jav_obj = file_writer.create_folder_for_existing_jav(update_dict)
    except KeyError as e:
        _car = update_dict.get('car', 'Unknown')
        update_dict.append(json.dumps({'log': f'error: {e}, skipping {_car}'}))
    # write images
    file_writer.write_images(jav_obj)
    # write nfo
    file_writer.write_nfo(jav_obj)
    # move video file
    jav_obj = file_writer.move_existing_file(jav_obj)

    return jsonify({'success': jav_obj})  # post updated jav_obj back to UI 
开发者ID:ddd354,项目名称:JAVOneStop,代码行数:27,代码来源:local_manager.py

示例15: restructure_jav

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import get_data [as 别名]
def restructure_jav():
    req_data = json.loads(request.get_data() or '{}')
    update_dict = req_data['update_dict']

    file_writer = EmbyFileStructure(return_default_config_string('file_path'))
     # file structure operations
    try:
        jav_obj = file_writer.create_folder_for_existing_jav(update_dict)
    except KeyError as e:
        _car = update_dict.get('car', 'Unknown')
        update_dict.append(json.dumps({'log': f'error: {e}, skipping {_car}'}))
    # write images
    file_writer.write_images(jav_obj)
    # write nfo
    file_writer.write_nfo(jav_obj)
    # move video file
    jav_obj = file_writer.move_existing_file(jav_obj)

    return jsonify({'success': 'good'}) 
开发者ID:ddd354,项目名称:JAVOneStop,代码行数:21,代码来源:local_manager.py


注:本文中的flask.request.get_data方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。