本文整理汇总了Python中werkzeug.wrappers.Request.get_data方法的典型用法代码示例。如果您正苦于以下问题:Python Request.get_data方法的具体用法?Python Request.get_data怎么用?Python Request.get_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类werkzeug.wrappers.Request
的用法示例。
在下文中一共展示了Request.get_data方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: application
# 需要导入模块: from werkzeug.wrappers import Request [as 别名]
# 或者: from werkzeug.wrappers.Request import get_data [as 别名]
def application(environ, start_response):
# The WSGI server puts content length and type in the environment
# even when not provided with the request. Drop them if they are empty.
if environ.get('CONTENT_LENGTH') == '':
del environ['CONTENT_LENGTH']
if environ.get('CONTENT_TYPE') == '':
del environ['CONTENT_TYPE']
wrequest = WerkzeugRequest(environ)
data = wrequest.get_data()
request = Request(
method=wrequest.method,
url=wrequest.url,
headers=wrequest.headers,
data=data,
)
prepared = request.prepare()
stream = streams.build_output_stream(
args, env, prepared, response=None,
output_options=args.output_options)
streams.write_stream(stream, env.stdout, env.stdout_isatty)
# When there is data in the request, give the next one breathing room.
if data:
print("\n", file=env.stdout)
# Make dreams come true.
response = Response(headers={'Server': server})
return response(environ, start_response)
示例2: _request_signature
# 需要导入模块: from werkzeug.wrappers import Request [as 别名]
# 或者: from werkzeug.wrappers.Request import get_data [as 别名]
def _request_signature(self, environ, digest):
h = hmac.new(
self._secret_key.encode('utf8'),
self.string_to_sign(environ).encode('utf8'),
digest,
)
request = Request(environ)
if 'wsgi.input' in environ:
h.update(request.get_data())
return digest().name + ' ' + base64.b64encode(h.digest()).decode('utf8')
示例3: __call__
# 需要导入模块: from werkzeug.wrappers import Request [as 别名]
# 或者: from werkzeug.wrappers.Request import get_data [as 别名]
def __call__(self, environ, start_response):
request = Request(environ)
try:
name, args, kwargs = loads(request.get_data(cache=True))
debug('calling function: "%s"', name)
result = self.rpc()(name, *args, **kwargs)
execution_error = None
except Exception, e:
execution_error = ErrorMessage.from_exception(e, address=request.host_url)
result = None
error('error: %s, traceback: \n%s', e, traceback.format_exc())
示例4: app
# 需要导入模块: from werkzeug.wrappers import Request [as 别名]
# 或者: from werkzeug.wrappers.Request import get_data [as 别名]
def app(request: Request):
if request.path != '/':
return Response(
json.dumps({
'error': 'not-found',
'message': "page not found; there's only one path: /"
}),
status=404
)
elif request.method.upper() != 'POST':
return Response(
json.dumps({
'error': 'method-not-allowed',
'message': 'only POST method is allowed'
}),
status=405
)
elif request.mimetype not in {'text/html', 'application/xhtml+xml'}:
return Response(
json.dumps({
'error': 'bad-request',
'message': 'content has to be HTML'
}),
status=400
)
matched = request.accept_mimetypes.best_match(SUPPORTED_TYPES.keys())
if not matched:
return Response(
json.dumps({
'error': 'not-acceptable',
'message': 'unsupported type; the list of supported '
'types: ' + ', '.join(SUPPORTED_TYPES)
}),
status=406
)
html = HTML(string=request.get_data(as_text=True))
pdf_buffer = io.BytesIO()
SUPPORTED_TYPES[matched](html, pdf_buffer)
pdf_buffer.seek(0)
return Response(pdf_buffer, mimetype=matched)