Use aiohttp.web.json_response()
Avoids explicit setting of JSON content type, handles serialization to JSON.
This commit is contained in:
parent
54baf29d51
commit
139ec1670c
1 changed files with 7 additions and 3 deletions
|
@ -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):
|
||||||
|
|
Loading…
Reference in a new issue