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


Python request.content_length方法代碼示例

本文整理匯總了Python中flask.request.content_length方法的典型用法代碼示例。如果您正苦於以下問題:Python request.content_length方法的具體用法?Python request.content_length怎麽用?Python request.content_length使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在flask.request的用法示例。


在下文中一共展示了request.content_length方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _extract_data

# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import content_length [as 別名]
def _extract_data(request):
    """ Return Dict with extracted data from request

        :param request: Flask.request with data to process
    """
    if request.content_length == 0:
        raise WebhookException(consts.NO_DATA_MESSAGE, status_code=400)
    if request.content_length > consts.MAX_CONTENT_MB:
        raise WebhookException(
            consts.MESSAGE_TOO_BIG.format(content_length=request.content_length,
                                          max_bytes=consts.MAX_CONTENT_MB),
            status_code=400)
    try:
        return request.get_json()
    except Exception:
        return {"message": request.get_data(as_text=True)} 
開發者ID:GoogleCloudPlatform,項目名稱:professional-services,代碼行數:18,代碼來源:main.py

示例2: create_binary

# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import content_length [as 別名]
def create_binary():
    print(request.args)
    print(request.data)
    print(request.files)
    print(request.headers)
    
    if request.content_type == "application/octet-stream":
        data = request.get_data()
        print(len(data))
        print(data[:20])
        return jsonify({
            'msg': 'success',
            'request.content_type': request.content_type,
            'request.content_length': request.content_length,
            'len': len(data),
            'first': data[:20].decode('unicode_escape'), # convert bytes to string which can be send in JSON
        })
    else:
        return jsonify({
            'msg': '415 Unsupported Media Type ;)',
            'request.content_type': request.content_type,
        }) 
開發者ID:furas,項目名稱:python-examples,代碼行數:24,代碼來源:app.py

示例3: register_extensions

# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import content_length [as 別名]
def register_extensions(app):
    db.init_app(app)
    executor.init_app(app)
    basic_auth.init_app(app)

    @app.before_request
    def enable_form_raw_cache():
        # Workaround to allow unparsed request body to be be read from cache
        # This is required to validate a signature on webhooks
        # This MUST go before Sentry integration as sentry triggers form parsing
        if not config.IS_TEST and (
                request.path.startswith('/api/v1/slack/') or request.path.startswith('/api/v1/poli_payments_webhook/')):
            if request.content_length > 1024 * 1024:  # 1mb
                # Payload too large
                return make_response(jsonify({'message': 'Payload too large'})), 413
            request.get_data(parse_form_data=False, cache=True)

    # limiter.init_app(app)

    CORS(app, resources={r"/api/*": {"origins": "*"}})

    celery_app.conf.update(app.config)
    if not config.IS_TEST:
        sentry_sdk.init(app.config['SENTRY_SERVER_DSN'], integrations=[FlaskIntegration()], release=config.VERSION)

    print('celery joined on {} at {}'.format(
        app.config['REDIS_URL'], datetime.utcnow())) 
開發者ID:teamsempo,項目名稱:SempoBlockchain,代碼行數:29,代碼來源:__init__.py

示例4: transform_runner

# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import content_length [as 別名]
def transform_runner(transform_name):
    if transform_name not in application.transforms:
        return Response(application.four_o_four, status=404)
    if not request.content_length:
        return Response('Yes?', status=200)
    return do_transform(application.transforms[transform_name])


# To run Flask standalone just type `python -m canari.tas.plume` 
開發者ID:redcanari,項目名稱:canari3,代碼行數:11,代碼來源:plume.py

示例5: upload_zip

# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import content_length [as 別名]
def upload_zip():
    # param_dict:存放請求參數
    param_dict = dict.fromkeys(upload_request_param_list, None)
    start_time = time.time()

    file_size = request.content_length

    try:
        # 以表單形式發送數據
        parameter = request.form
        for param in upload_request_param_list:
            param_dict[param] = parameter.get(param)
    except:
        raise Exception 
開發者ID:itaa,項目名稱:soja-box,代碼行數:16,代碼來源:soja_upload_API.py

示例6: file

# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import content_length [as 別名]
def file():
    print(request.args)
    print(request.data)
    print(request.files)
    print(request.headers)
    
    file_ = request.files.get('file')

    if file_:
        #file_.save('output.pdf')
        data = file_.read()
        print(len(data))
        print(data[:20])
        return jsonify({
            'msg': 'success',
            'request.content_type': request.content_type,
            'request.content_length': request.content_length,
            'filename': file_.filename,
            'len': len(data),
            'first': data[:20].decode('unicode_escape'), # convert bytes to string which can be send in JSON
        })
    else:
        return jsonify({
            'msg': 'no file',
            'request.content_type': request.content_type,
        }) 
開發者ID:furas,項目名稱:python-examples,代碼行數:28,代碼來源:app.py

示例7: post

# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import content_length [as 別名]
def post():
        global post_connected
        global rtt_queue
        
        #print('IN POST')
        response = {}
        response['status'] = 200
        
        if request.method == 'POST':
            try:
                data = request.get_json()

                if data == None:
                    # this should raise an HTTPException
                    abort(400, 'POST Data was not JSON')

                if request.content_length < 2400 and request.content_length != 0:
                    #print("Received Post: ", str(data))
                    
                    response['Type'] = data['Type']
                    
                    if data['Type'] == 'P':
                        
                        rtt_lock.acquire()
                        rtt_queue = data
                        rtt_lock.release()
                        
                        response['Data'] = {}
                        while not post_queue.empty():
                            action_tuple = ClientThread.get_from_post_queue()
                            #print('Action Tuple To Send To Dota: ', action_tuple)
                            if action_tuple:
                                response['Data'][str(action_tuple[0])] = {}
                                response['Data'][str(action_tuple[0])][str(action_tuple[1])] = action_tuple[2]
                    elif data['Type'] == 'X':
                        post_connected = True
                        
                    response['Time'] = data['Time']
                else:
                    print("Request too long", request.content_length)
                    response = {"status": 413, "content_length": request.content_length, "content": data}
                    return jsonify(response)
            except:
                traceback.print_exc()
                response['status'] = 500
        else:
            response['status'] = 401
            abort(400, 'Request Method is not POST')

        #print('SENDING RESPONSE:\n', response)
        return jsonify(response) 
開發者ID:pydota2,項目名稱:pydota2_archive,代碼行數:53,代碼來源:client_connector.py

示例8: us_signin_send_code

# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import content_length [as 別名]
def us_signin_send_code():
    """
    Send code view.
    This takes an identity (as configured in USER_IDENTITY_ATTRIBUTES)
    and a method request to send a code.
    """
    form_class = _security.us_signin_form

    if request.is_json:
        if request.content_length:
            form = form_class(MultiDict(request.get_json()), meta=suppress_form_csrf())
        else:
            form = form_class(formdata=None, meta=suppress_form_csrf())
    else:
        form = form_class(meta=suppress_form_csrf())
    form.submit_send_code.data = True

    code_methods = _compute_code_methods()

    if form.validate_on_submit():
        code_sent, msg = _send_code_helper(form)
        if _security._want_json(request):
            # Not authenticated yet - so don't send any user info.
            return base_render_json(
                form, include_user=False, error_status_code=500 if msg else 400
            )

        return _security.render_template(
            config_value("US_SIGNIN_TEMPLATE"),
            us_signin_form=form,
            available_methods=config_value("US_ENABLED_METHODS"),
            code_methods=code_methods,
            chosen_method=form.chosen_method.data,
            code_sent=code_sent,
            skip_loginmenu=True,
            **_security._run_ctx_processor("us_signin")
        )

    # Here on GET or failed validation
    if _security._want_json(request):
        payload = {
            "available_methods": config_value("US_ENABLED_METHODS"),
            "code_methods": code_methods,
            "identity_attributes": get_identity_attributes(),
        }
        return base_render_json(form, include_user=False, additional=payload)

    return _security.render_template(
        config_value("US_SIGNIN_TEMPLATE"),
        us_signin_form=form,
        available_methods=config_value("US_ENABLED_METHODS"),
        code_methods=code_methods,
        skip_loginmenu=True,
        **_security._run_ctx_processor("us_signin")
    ) 
開發者ID:Flask-Middleware,項目名稱:flask-security,代碼行數:57,代碼來源:unified_signin.py

示例9: us_verify_send_code

# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import content_length [as 別名]
def us_verify_send_code():
    """
    Send code during verify.
    """
    form_class = _security.us_verify_form

    if request.is_json:
        if request.content_length:
            form = form_class(MultiDict(request.get_json()), meta=suppress_form_csrf())
        else:
            form = form_class(formdata=None, meta=suppress_form_csrf())
    else:
        form = form_class(meta=suppress_form_csrf())
    form.submit_send_code.data = True

    code_methods = _compute_code_methods()

    if form.validate_on_submit():
        code_sent, msg = _send_code_helper(form)
        if _security._want_json(request):
            # Not authenticated yet - so don't send any user info.
            return base_render_json(
                form, include_user=False, error_status_code=500 if msg else 400
            )

        return _security.render_template(
            config_value("US_VERIFY_TEMPLATE"),
            us_verify_form=form,
            available_methods=config_value("US_ENABLED_METHODS"),
            code_methods=code_methods,
            chosen_method=form.chosen_method.data,
            code_sent=code_sent,
            skip_login_menu=True,
            send_code_to=get_url(
                _security.us_verify_send_code_url,
                qparams={"next": propagate_next(request.url)},
            ),
            **_security._run_ctx_processor("us_verify")
        )

    # Here on GET or failed validation
    if _security._want_json(request):
        payload = {
            "available_methods": config_value("US_ENABLED_METHODS"),
            "code_methods": code_methods,
        }
        return base_render_json(form, additional=payload)

    return _security.render_template(
        config_value("US_VERIFY_TEMPLATE"),
        us_verify_form=form,
        available_methods=config_value("US_ENABLED_METHODS"),
        code_methods=code_methods,
        skip_login_menu=True,
        send_code_to=get_url(
            _security.us_verify_send_code_url,
            qparams={"next": propagate_next(request.url)},
        ),
        **_security._run_ctx_processor("us_verify")
    ) 
開發者ID:Flask-Middleware,項目名稱:flask-security,代碼行數:62,代碼來源:unified_signin.py

示例10: us_verify

# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import content_length [as 別名]
def us_verify():
    """
    Re-authenticate to reset freshness time.
    This is likely the result of a reauthn_handler redirect, which
    will have filled in ?next=xxx - which we want to carefully not lose as we
    go through these steps.
    """
    form_class = _security.us_verify_form

    if request.is_json:
        if request.content_length:
            form = form_class(MultiDict(request.get_json()), meta=suppress_form_csrf())
        else:
            form = form_class(formdata=None, meta=suppress_form_csrf())
    else:
        form = form_class(meta=suppress_form_csrf())
    form.submit.data = True

    code_methods = _compute_code_methods()

    if form.validate_on_submit():
        # verified - so set freshness time.
        session["fs_paa"] = time.time()

        if _security._want_json(request):
            return base_render_json(form, include_auth_token=True)

        do_flash(*get_message("REAUTHENTICATION_SUCCESSFUL"))
        return redirect(get_post_verify_redirect())

    # Here on GET or failed POST validate
    if _security._want_json(request):
        payload = {
            "available_methods": config_value("US_ENABLED_METHODS"),
            "code_methods": code_methods,
        }
        return base_render_json(form, additional=payload)

    # On error - wipe code
    form.passcode.data = None
    return _security.render_template(
        config_value("US_VERIFY_TEMPLATE"),
        us_verify_form=form,
        code_methods=code_methods,
        skip_login_menu=True,
        send_code_to=get_url(
            _security.us_verify_send_code_url,
            qparams={"next": propagate_next(request.url)},
        ),
        **_security._run_ctx_processor("us_verify")
    ) 
開發者ID:Flask-Middleware,項目名稱:flask-security,代碼行數:53,代碼來源:unified_signin.py


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