当前位置: 首页>>代码示例>>Python>>正文


Python request.data方法代码示例

本文整理汇总了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 
开发者ID:wechatpy,项目名称:wechatpy,代码行数:27,代码来源:app.py

示例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.'}) 
开发者ID:BennyThink,项目名称:ServerSan,代码行数:20,代码来源:webhook.py

示例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') 
开发者ID:jaywink,项目名称:social-relay,代码行数:18,代码来源:views.py

示例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 
开发者ID:dataiku,项目名称:dataiku-contrib,代码行数:20,代码来源:app.py

示例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) 
开发者ID:dataiku,项目名称:dataiku-contrib,代码行数:27,代码来源:app.py

示例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) 
开发者ID:honmaple,项目名称:maple-file,代码行数:18,代码来源:router.py

示例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) 
开发者ID:honmaple,项目名称:maple-file,代码行数:19,代码来源:router.py

示例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) 
开发者ID:honmaple,项目名称:maple-file,代码行数:20,代码来源:router.py

示例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) 
开发者ID:honmaple,项目名称:maple-file,代码行数:21,代码来源:router.py

示例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 
开发者ID:rucio,项目名称:rucio,代码行数:27,代码来源:subscription.py

示例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 
开发者ID:rucio,项目名称:rucio,代码行数:27,代码来源:replica.py

示例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 
开发者ID:rucio,项目名称:rucio,代码行数:26,代码来源:lifetime_exception.py

示例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 
开发者ID:rucio,项目名称:rucio,代码行数:27,代码来源:did.py

示例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") 
开发者ID:rucio,项目名称:rucio,代码行数:24,代码来源:rule.py

示例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) 
开发者ID:wechatpy,项目名称:wechatpy,代码行数:41,代码来源:app.py


注:本文中的flask.request.data方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。