本文整理匯總了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})
示例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})
示例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})
示例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})
示例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
示例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
示例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
示例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)
示例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
示例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
示例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
示例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))
示例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 來獲取用戶信息
示例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
示例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