本文整理匯總了Python中flask.request.data方法的典型用法代碼示例。如果您正苦於以下問題:Python request.data方法的具體用法?Python request.data怎麽用?Python request.data使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類flask.request
的用法示例。
在下文中一共展示了request.data方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: wechat
# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import data [as 別名]
def wechat():
signature = request.args.get("msg_signature", "")
timestamp = request.args.get("timestamp", "")
nonce = request.args.get("nonce", "")
crypto = WeChatCrypto(TOKEN, EncodingAESKey, CorpId)
if request.method == "GET":
echo_str = request.args.get("echostr", "")
try:
echo_str = crypto.check_signature(signature, timestamp, nonce, echo_str)
except InvalidSignatureException:
abort(403)
return echo_str
else:
try:
msg = crypto.decrypt_message(request.data, signature, timestamp, nonce)
except (InvalidSignatureException, InvalidCorpIdException):
abort(403)
msg = parse_message(msg)
if msg.type == "text":
reply = create_reply(msg.content, msg).render()
else:
reply = create_reply("Can not handle this for now", msg).render()
res = crypto.encrypt_message(reply, nonce, timestamp)
return res
示例2: create
# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import data [as 別名]
def create():
try:
d = json.loads(request.data)
except ValueError:
return json.dumps({'status': 1, 'info': 'request failed.'})
current_ts = time.time()
_id = False
d.update(timestamp=current_ts)
perm = ts_can_insert(d.get('auth'), current_ts) and token_can_insert(d.get('auth'))
if perm:
_id = col.insert_one(d).inserted_id
if _id:
return json.dumps({'status': 0, 'info': 'success'})
else:
return json.dumps({'status': 2, 'info': 'op too frequent or invalid token.'})
示例3: receive_public
# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import data [as 別名]
def receive_public():
if not request.data:
return abort(404)
# Queue to rq for processing
public_queue.enqueue("workers.receive.process", request.data, timeout=app.config.get("RELAY_WORKER_TIMEOUT"))
# Log statistics
log_receive_statistics(request.remote_addr)
# return 200 whatever
data = {
'result': 'ok',
}
js = json.dumps(data)
return Response(js, status=200, mimetype='application/json')
示例4: display_new_token
# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import data [as 別名]
def display_new_token():
data = {
"username" : request.args.get("powerbi-username"),
"password" : request.args.get("powerbi-password"),
"client_id" : request.args.get("powerbi-client-id"),
"client_secret": request.args.get("powerbi-client-secret"),
"resource" : request.args.get("powerbi-resource", "https://analysis.windows.net/powerbi/api"),
"grant_type" : request.args.get("powerbi-grant-type", "password"),
"scope" : request.args.get("powerbi-scope", "openid")
}
response = requests.post('https://login.microsoftonline.com/common/oauth2/token', data=data)
o = {}
#o["powerbi-auth-response"] = response.json()
o["powerbi-access-token"] = response.json().get("access_token")
return json.dumps(o)
# Helper functions to interact with DSS Project Variables
示例5: get_token
# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import data [as 別名]
def get_token():
# Read in the existing conf
dss = dataiku.api_client()
project = dss.get_project(dataiku.default_project_key())
variables = project.get_variables()["standard"]
conf = variables.get("powerbi-settings", None)
# Decrypt
key = request.args.get("api-key")
pbi = {}
pbi["username"] = conf["username"]
pbi["password"] = decrypt_string(conf["password"], key)
pbi["client_id"] = conf["client_id"]
pbi["client_secret"] = decrypt_string(conf["client_secret"], key)
pbi["resource"] = conf["resource"]
pbi["grant_type"] = conf["grant_type"]
pbi["scope"] = conf["scope"]
# Get the token
response = requests.post('https://login.microsoftonline.com/common/oauth2/token', data=pbi)
o = {}
o["token"] = response.json().get("access_token")
return json.dumps(o)
示例6: post
# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import data [as 別名]
def post(self):
'''
新建相冊
'''
post_data = request.data
user = request.user
name = post_data.pop('name', None)
description = post_data.pop('description', None)
if name is None:
return HTTP.BAD_REQUEST(message='相冊名稱不能為空')
album = Album(name=name, user=user)
if description is not None:
album.description = description
album.save()
serializer = AlbumSerializer(album)
return HTTP.OK(data=serializer.data)
示例7: put
# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import data [as 別名]
def put(self, pk):
'''
修改相冊
'''
post_data = request.data
user = request.user
name = post_data.pop('name', None)
description = post_data.pop('description', None)
album = Album.query.filter_by(id=pk, user=user).get_or_404('相冊不存在')
if name is not None:
album.name = name
if description is not None:
album.description = description
album.save()
serializer = AlbumSerializer(album)
album.delete()
return HTTP.OK(data=serializer.data)
示例8: get
# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import data [as 別名]
def get(self):
'''
獲取圖片列表
'''
query_dict = request.data
user = request.user
page, number = self.page_info
keys = ['name', 'description']
order_by = gen_order_by(query_dict, keys)
filter_dict = gen_filter_dict(query_dict, keys, user=user)
album = query_dict.pop('album', None)
if album is not None:
filter_dict.update(album__id=album)
images = Image.query.filter_by(
**filter_dict).order_by(*order_by).paginate(page, number)
serializer = ImageSerializer(images.items, True)
pageinfo = PageInfo(images)
return HTTP.OK(data=serializer.data, pageinfo=pageinfo)
示例9: delete
# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import data [as 別名]
def delete(self, pk):
'''
刪除圖片
'''
user = request.user
image = Image.query.filter_by(id=pk, user=user).get_or_404('圖片不存在')
serializer = ImageSerializer(image)
img_path = os.path.join(current_app.config['UPLOAD_FOLDER_ROOT'],
image.url)
# 刪除原圖
if os.path.exists(img_path):
os.remove(img_path)
# 刪除縮略圖
thumb_path = os.path.join(current_app.config['UPLOAD_FOLDER_ROOT'],
image.url.replace('photo', 'thumb'))
if os.path.exists(thumb_path):
os.remove(thumb_path)
image.delete()
return HTTP.OK(data=serializer.data)
示例10: get
# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import data [as 別名]
def get(self, account=None, name=None):
"""
Retrieve a subscription.
.. :quickref: Subscription; Get subscriptions.
:param account: The account name.
:param name: The subscription name.
:resheader Content-Type: application/x-json-stream
:status 200: OK.
:status 401: Invalid Auth Token.
:status 404: Subscription Not Found.
:status 406: Not Acceptable.
:status 500: Internal Error.
:returns: Line separated list of dictionaries with subscription information.
"""
try:
data = ""
for subscription in list_subscriptions(name=name, account=account):
data += dumps(subscription, cls=APIEncoder) + '\n'
return Response(data, content_type="application/x-json-stream")
except SubscriptionNotFound as error:
return generate_http_error_flask(404, 'SubscriptionNotFound', error.args[0])
except Exception as error:
return error, 500
示例11: get
# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import data [as 別名]
def get(self, scope, name):
"""
List dataset replicas.
.. :quickref: DatasetReplicas; List dataset replicas.
:query deep: Flag to ennable lookup at the file level.
:resheader Content-Type: application/x-json-stream
:status 200: OK.
:status 401: Invalid auth token.
:status 406: Not Acceptable.
:status 500: Internal Error.
:returns: A dictionary containing all replicas information.
"""
deep = request.args.get('deep', False)
try:
data = ""
for row in list_dataset_replicas(scope=scope, name=name, deep=deep):
data += dumps(row, cls=APIEncoder) + '\n'
return Response(data, content_type='application/x-json-stream')
except RucioException as error:
return generate_http_error_flask(500, error.__class__.__name__, error.args[0])
except Exception as error:
print(format_exc())
return error, 500
示例12: get
# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import data [as 別名]
def get(self):
"""
Retrieve all exceptions.
.. :quickref: LifetimeException; Get all exceptions.
:resheader Content-Type: application/x-json-stream
:status 200: OK.
:status 401: Invalid Auth Token.
:status 404: Lifetime Exception Not Found.
:status 406: Not Acceptable.
:status 500: Internal Error.
"""
try:
data = ""
for exception in list_exceptions():
data += dumps(exception, cls=APIEncoder) + '\n'
return Response(data, content_type="application/x-json-stream")
except LifetimeExceptionNotFound as error:
return generate_http_error_flask(404, 'LifetimeExceptionNotFound', error.args[0])
except RucioException as error:
return generate_http_error_flask(500, error.__class__.__name__, error.args[0])
except Exception as error:
return error, 500
示例13: get
# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import data [as 別名]
def get(self, scope, name):
"""
Return all associated rules of a file.
.. :quickref: AssociatedRules; List associated rules of DID.
:resheader Content-Type: application/x-json-stream
:param scope: The scope of the data identifier.
:param name: The name of the data identifier.
:status 200: DID found
:status 401: Invalid Auth Token
:status 404: DID not found
:status 406: Not Acceptable
:status 500: Database Exception
:returns: List of associated rules.
"""
try:
data = ""
for rule in list_associated_replication_rules_for_file(scope=scope, name=name):
data += dumps(rule, cls=APIEncoder) + '\n'
return Response(data, content_type="application/x-json-stream")
except RucioException as error:
return generate_http_error_flask(500, error.__class__.__name__, error.args[0])
except Exception as error:
return error, 500
示例14: get
# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import data [as 別名]
def get(self, rule_id):
""" get locks for a given rule_id.
.. :quickref: ReplicaLocks; get locks by rule id
:status 200: Rule found
:status 406: Not Acceptable
:status 500: Database Exception
:returns: JSON dict containing informations about the requested user.
"""
try:
locks = get_replica_locks_for_rule_id(rule_id)
except RucioException as error:
return generate_http_error_flask(500, error.__class__.__name__, error.args[0])
except Exception as error:
return error, 500
data = ""
for lock in locks:
data += dumps(lock, cls=APIEncoder) + '\n'
return Response(data, content_type="application/x-json-stream")
示例15: wechat
# 需要導入模塊: from flask import request [as 別名]
# 或者: from flask.request import data [as 別名]
def wechat():
signature = request.args.get("signature", "")
timestamp = request.args.get("timestamp", "")
nonce = request.args.get("nonce", "")
encrypt_type = request.args.get("encrypt_type", "raw")
msg_signature = request.args.get("msg_signature", "")
try:
check_signature(TOKEN, signature, timestamp, nonce)
except InvalidSignatureException:
abort(403)
if request.method == "GET":
echo_str = request.args.get("echostr", "")
return echo_str
# POST request
if encrypt_type == "raw":
# plaintext mode
msg = parse_message(request.data)
if msg.type == "text":
reply = create_reply(msg.content, msg)
else:
reply = create_reply("Sorry, can not handle this for now", msg)
return reply.render()
else:
# encryption mode
from wechatpy.crypto import WeChatCrypto
crypto = WeChatCrypto(TOKEN, AES_KEY, APPID)
try:
msg = crypto.decrypt_message(request.data, msg_signature, timestamp, nonce)
except (InvalidSignatureException, InvalidAppIdException):
abort(403)
else:
msg = parse_message(msg)
if msg.type == "text":
reply = create_reply(msg.content, msg)
else:
reply = create_reply("Sorry, can not handle this for now", msg)
return crypto.encrypt_message(reply.render(), nonce, timestamp)