From 600148e6d21215f15ec1a9b35fdb788032116f80 Mon Sep 17 00:00:00 2001 From: Alex Root Junior Date: Thu, 16 Nov 2017 17:56:27 +0200 Subject: [PATCH] Check response content type. --- aiogram/bot/api.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/aiogram/bot/api.py b/aiogram/bot/api.py index 13ff07e7..7705e52a 100644 --- a/aiogram/bot/api.py +++ b/aiogram/bot/api.py @@ -50,6 +50,9 @@ async def _check_result(method_name, response): body = await response.text() log.debug(f"Response for {method_name}: [{response.status}] {body}") + if response.content_type != 'application/json': + raise exceptions.NetworkError(f"Invalid response with content type {response.content_type}: \"{body}\"") + try: result_json = await response.json(loads=json.loads) except ValueError: