本文整理汇总了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)}
示例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,
})
示例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()))
示例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`
示例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
示例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,
})
示例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)
示例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")
)
示例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")
)
示例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")
)