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


Python request.json方法代码示例

本文整理汇总了Python中flask.request.json方法的典型用法代码示例。如果您正苦于以下问题:Python request.json方法的具体用法?Python request.json怎么用?Python request.json使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在flask.request的用法示例。


在下文中一共展示了request.json方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: use_of_force

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import json [as 别名]
def use_of_force():
    username = request.authorization.username
    extractor = Extractor.query.filter_by(username=username).first()
    department = extractor.first_department()
    request_json = request.json
    added_rows = 0
    updated_rows = 0

    uof_class = getattr(importlib.import_module("comport.data.models"), "UseOfForceIncident{}".format(department.short_name))

    for incident in request_json['data']:
        added = uof_class.add_or_update_incident(department, incident)
        if added is True:
            added_rows += 1
        elif added is False:
            updated_rows += 1

    extractor.next_month = None
    extractor.next_year = None
    extractor.save()
    return json.dumps({"added": added_rows, "updated": updated_rows}) 
开发者ID:codeforamerica,项目名称:comport,代码行数:23,代码来源:views.py

示例2: officer_involved_shooting

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import json [as 别名]
def officer_involved_shooting():
    username = request.authorization.username
    extractor = Extractor.query.filter_by(username=username).first()
    department = extractor.first_department()
    request_json = request.json
    added_rows = 0
    updated_rows = 0

    ois_class = getattr(importlib.import_module("comport.data.models"), "OfficerInvolvedShooting{}".format(department.short_name))

    for incident in request_json['data']:
        added = ois_class.add_or_update_incident(department, incident)
        if added is True:
            added_rows += 1
        elif added is False:
            updated_rows += 1

    extractor.next_month = None
    extractor.next_year = None
    extractor.save()
    return json.dumps({"added": added_rows, "updated": updated_rows}) 
开发者ID:codeforamerica,项目名称:comport,代码行数:23,代码来源:views.py

示例3: complaints

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import json [as 别名]
def complaints():
    username = request.authorization.username
    extractor = Extractor.query.filter_by(username=username).first()
    department = extractor.first_department()
    request_json = request.json
    added_rows = 0
    updated_rows = 0

    complaint_class = getattr(importlib.import_module("comport.data.models"), "CitizenComplaint{}".format(department.short_name))

    for incident in request_json['data']:
        added = complaint_class.add_or_update_incident(department, incident)
        if added is True:
            added_rows += 1
        elif added is False:
            updated_rows += 1

    extractor.next_month = None
    extractor.next_year = None
    extractor.save()
    return json.dumps({"added": added_rows, "updated": updated_rows}) 
开发者ID:codeforamerica,项目名称:comport,代码行数:23,代码来源:views.py

示例4: pursuits

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import json [as 别名]
def pursuits():
    username = request.authorization.username
    extractor = Extractor.query.filter_by(username=username).first()
    department = extractor.first_department()
    request_json = request.json
    added_rows = 0
    updated_rows = 0

    pursuit_class = getattr(importlib.import_module("comport.data.models"), "Pursuit{}".format(department.short_name))

    for incident in request_json['data']:
        added = pursuit_class.add_or_update_incident(department, incident)
        if added is True:
            added_rows += 1
        elif added is False:
            updated_rows += 1

    extractor.next_month = None
    extractor.next_year = None
    extractor.save()
    return json.dumps({"added": added_rows, "updated": updated_rows}) 
开发者ID:codeforamerica,项目名称:comport,代码行数:23,代码来源:views.py

示例5: messages

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import json [as 别名]
def messages():
    # Main bot message handler.
    if "application/json" in request.headers["Content-Type"]:
        body = request.json
    else:
        return Response(status=415)

    activity = Activity().deserialize(body)
    auth_header = (
        request.headers["Authorization"] if "Authorization" in request.headers else ""
    )

    async def aux_func(turn_context):
        await BOT.on_turn(turn_context)

    try:
        task = LOOP.create_task(
            ADAPTER.process_activity(activity, auth_header, aux_func)
        )
        LOOP.run_until_complete(task)
        return Response(status=201)
    except Exception as exception:
        raise exception 
开发者ID:microsoft,项目名称:botbuilder-python,代码行数:25,代码来源:app.py

示例6: messages

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import json [as 别名]
def messages():
    """Main bot message handler."""
    if "application/json" in request.headers["Content-Type"]:
        body = request.json
    else:
        return Response(status=415)

    activity = Activity().deserialize(body)
    auth_header = (
        request.headers["Authorization"] if "Authorization" in request.headers else ""
    )

    async def aux_func(turn_context):
        await BOT.on_turn(turn_context)

    try:
        task = LOOP.create_task(
            ADAPTER.process_activity(activity, auth_header, aux_func)
        )
        LOOP.run_until_complete(task)
        return Response(status=201)

    except Exception as exception:
        raise exception 
开发者ID:microsoft,项目名称:botbuilder-python,代码行数:26,代码来源:main.py

示例7: messages

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import json [as 别名]
def messages():
    # Main bot message handler.
    if "application/json" in request.headers["Content-Type"]:
        body = request.json
    else:
        return Response(status=415)

    activity = Activity().deserialize(body)
    auth_header = (
        request.headers["Authorization"] if "Authorization" in request.headers else ""
    )

    try:
        task = LOOP.create_task(
            ADAPTER.process_activity(activity, auth_header, BOT.on_turn)
        )
        LOOP.run_until_complete(task)
        return Response(status=201)
    except Exception as exception:
        raise exception 
开发者ID:microsoft,项目名称:botbuilder-python,代码行数:22,代码来源:app.py

示例8: home

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import json [as 别名]
def home():
    if request.method == "POST":
        #do back end things here and then return what we want, take it back in a success function in JS and update the page.
        heroes = [name.encode('UTF8') for name in request.json['heroes']]
        radiant = [get_hero_id(hero) for hero in heroes[:5] if get_hero_id(hero)]
        dire = [get_hero_id(hero) for hero in heroes[5:] if get_hero_id(hero)]
        mmr = int(request.json['mmr'])

        text = query(mmr, radiant, dire)

        if isinstance(text, list):
            text = ''.join([str(hero[0]) + ': ' + str(round(hero[1][0] * 100, 2))+'% win rate. <br>' for hero in text[:10]])

        return text

    hero_names = get_full_hero_list()
    radiant_heroes, dire_heroes = get_hero_factions()
    edited_names = [name.replace(" ", "_").replace("\'", "").lower() for name in hero_names]
    return render_template('main2.html', hero_names=sorted(hero_names), edited_names=sorted(edited_names), radiant_heroes=radiant_heroes, dire_heroes=dire_heroes) 
开发者ID:andreiapostoae,项目名称:dota2-predictor,代码行数:21,代码来源:app.py

示例9: process_data

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import json [as 别名]
def process_data(self, request):
        if not request.json:
            abort(415)
        endpoint_config = self.__endpoint['config']
        if request.method.upper() not in [method.upper() for method in endpoint_config['HTTPMethods']]:
            abort(405)
        try:
            log.info("CONVERTER CONFIG: %r", endpoint_config['converter'])
            converter = self.__endpoint['converter'](endpoint_config['converter'])
            converted_data = converter.convert(config=endpoint_config['converter'], data=request.get_json())
            self.send_to_storage(self.__name, converted_data)
            log.info("CONVERTED_DATA: %r", converted_data)
            return "OK", 200
        except Exception as e:
            log.exception("Error while post to anonymous handler: %s", e)
            return "", 500 
开发者ID:thingsboard,项目名称:thingsboard-gateway,代码行数:18,代码来源:rest_connector.py

示例10: score

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import json [as 别名]
def score():
    if request.headers['Content-Type'] != 'application/json':
        resp = Response('Unssuported content type, expected application/json', status=500);
        return resp
    if (not request.json.has_key('text')):
        resp = Response('Bad request: missing "text" field in JSON body', status=500);
        return resp
    if (not request.json.has_key('entities')):
        resp = Response('Bad request: missing "entities" field in JSON body', status=500);
        return resp
    
    text = request.json['text']
    entities = request.json['entities']
    try:
        scorerResult = scorer.evaluate_score(text, entities)
        resp = jsonify(scorer_result_to_response_format(scorerResult))
        resp.status_code = 200
        return resp
    except Exception as e:
        resp = Response("Internal Server Error: %s"%e, status = 500)
        return resp 
开发者ID:CatalystCode,项目名称:corpus-to-graph-ml,代码行数:23,代码来源:app.py

示例11: update_model

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import json [as 别名]
def update_model():
    if request.headers['Content-Type'] != 'application/json':
        resp = Response('Unssuported content type, expected application/json', status=500);
        return resp
    if (not request.json.has_key('path')):
        resp = Response('Bad request: missing "path" field in JSON body', status=500);
        return resp
    
    path = request.json['path']
    try:
        scorer.load_model_from_url(path)
        resp = Response("", status=200);
        return resp
    except Exception as e:
        resp = Response("Internal Server Error: %s"%e, status = 500)
        return resp 
开发者ID:CatalystCode,项目名称:corpus-to-graph-ml,代码行数:18,代码来源:app.py

示例12: __call__

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import json [as 别名]
def __call__(self, form, field):
        if current_app.testing:
            return True

        if request.json:
            response = request.json.get('g-recaptcha-response', '')
        else:
            response = request.form.get('g-recaptcha-response', '')
        remote_ip = request.remote_addr

        if not response:
            raise ValidationError(field.gettext(self.message))

        if not self._validate_recaptcha(response, remote_ip):
            field.recaptcha_error = 'incorrect-captcha-sol'
            raise ValidationError(field.gettext(self.message)) 
开发者ID:jpush,项目名称:jbox,代码行数:18,代码来源:validators.py

示例13: create_developer

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import json [as 别名]
def create_developer():
    if not request.json or not 'platform_id' in request.json:
        abort(400)
    developer = Developer.query.filter_by(platform_id=request.json['platform_id'],
                                          platform=request.json['platform']).first()
    if 'desc' in request.json:
        desc = request.json['desc']
    else:
        desc = ''
    if developer is None:
        dev_key = generate_dev_key()
        developer = Developer(dev_key=dev_key,
                              platform=request.json['platform'],
                              platform_id=request.json['platform_id'],
                              username=request.json['dev_name'],
                              email=request.json['email'],
                              description=desc)
        developer.insert_to_db()
        return jsonify({'dev_key': developer.dev_key}), 201
    else:
        return jsonify({'created': False}), 304


# 通过 platform 和 platform_id 来获取用户信息 
开发者ID:jpush,项目名称:jbox,代码行数:26,代码来源:developers.py

示例14: modify_developer

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import json [as 别名]
def modify_developer(dev_key):
    developer = Developer.query.filter_by(dev_key=dev_key).first()
    if developer is None:
        abort(404)
    if 'name' in request.json:
        developer.username = request.json['name']
    if 'desc' in request.json:
        developer.description = request.json['desc']
    if 'avatar' in request.json:
        developer.avatar = request.json['avatar']
    if 'email' in request.json:
        developer.email = request.json['email']
    db.session.add(developer)
    try:
        db.session.commit()
        return jsonify({'modified': True}), 200
    except:
        db.session.rollback()
        abort(500)


# 在dev_key 下创建一个 channel 
开发者ID:jpush,项目名称:jbox,代码行数:24,代码来源:developers.py

示例15: modificate_integration

# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import json [as 别名]
def modificate_integration(dev_key, integration_id):
    if not request.json or not 'channel' in request.json:
        abort(400)
    developer = get_developer_with_devkey(dev_key)
    integration = Integration.query.filter_by(developer_id=developer.id, integration_id=integration_id).first()
    if integration is None:
        abort(400)
    integration.channel.channel = request.json['channel']
    if 'name' in request.json:
        integration.name = request.json['name']
    if 'description' in request.json:
        integration.description = request.json['description']
    if 'icon' in request.json:
        integration.icon = request.json['icon']
    db.session.add(integration)
    try:
        db.session.commit()
    except:
        db.session.rollback()
        abort(500)
    return jsonify({'modification': True}), 200


# 保存 github 集成,将所选的仓库与之前的仓库比较,新增则生成 webhook, 否则去掉之前的 webhook 
开发者ID:jpush,项目名称:jbox,代码行数:26,代码来源:developers.py


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