From 139ec1670cbeb6515665ab97035bdf9e0f2c5861 Mon Sep 17 00:00:00 2001 From: Jochen Kupperschmidt Date: Sun, 27 Dec 2020 14:37:54 +0100 Subject: [PATCH] Use `aiohttp.web.json_response()` Avoids explicit setting of JSON content type, handles serialization to JSON. --- matrix_webhook.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/matrix_webhook.py b/matrix_webhook.py index 903c4bb..12f47d2 100755 --- a/matrix_webhook.py +++ b/matrix_webhook.py @@ -56,9 +56,13 @@ async def handler(request): await CLIENT.login(MATRIX_PW) await send_room_message(room_id, content) - return web.Response(text='{"status": %i, "ret": "%s"}' % (status, ret), - content_type='application/json', - status=status) + return create_json_response(status, ret) + + +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):