Use aiohttp.web.json_response()

Avoids explicit setting of JSON content type, handles serialization to
JSON.
This commit is contained in:
Jochen Kupperschmidt 2020-12-27 14:37:54 +01:00
parent 54baf29d51
commit 139ec1670c

View file

@ -56,9 +56,13 @@ async def handler(request):
await CLIENT.login(MATRIX_PW) await CLIENT.login(MATRIX_PW)
await send_room_message(room_id, content) await send_room_message(room_id, content)
return web.Response(text='{"status": %i, "ret": "%s"}' % (status, ret), return create_json_response(status, ret)
content_type='application/json',
status=status)
def create_json_response(status, ret):
"""Create a JSON response."""
response_data = {'status': status, 'ret': ret}
return web.json_response(response_data, status=status)
async def send_room_message(room_id, content): async def send_room_message(room_id, content):