Python flask.request.content_length() Examples
The following are 10
code examples of flask.request.content_length().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
flask.request
, or try the search function
.
![](https://www.programcreek.com/common/static/images/search.png)
Example #1
Source File: main.py From professional-services with Apache License 2.0 | 6 votes |
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)}
Example #2
Source File: __init__.py From SempoBlockchain with GNU General Public License v3.0 | 5 votes |
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()))
Example #3
Source File: plume.py From canari3 with GNU General Public License v3.0 | 5 votes |
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`
Example #4
Source File: soja_upload_API.py From soja-box with MIT License | 5 votes |
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
Example #5
Source File: app.py From python-examples with MIT License | 5 votes |
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, })
Example #6
Source File: app.py From python-examples with MIT License | 5 votes |
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, })
Example #7
Source File: client_connector.py From pydota2_archive with Apache License 2.0 | 4 votes |
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)
Example #8
Source File: unified_signin.py From flask-security with MIT License | 4 votes |
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") )
Example #9
Source File: unified_signin.py From flask-security with MIT License | 4 votes |
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") )
Example #10
Source File: unified_signin.py From flask-security with MIT License | 4 votes |
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") )