From 846b881e522e4d35f18048ab9a442390fe787ee2 Mon Sep 17 00:00:00 2001 From: jesopo Date: Wed, 27 Feb 2019 15:16:08 +0000 Subject: [PATCH] Throw ValueError when utils.http.request tries to soup non-html/xml data --- src/utils/http.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/utils/http.py b/src/utils/http.py index f502301d..c246cdb9 100644 --- a/src/utils/http.py +++ b/src/utils/http.py @@ -62,9 +62,12 @@ def request(url: str, method: str="GET", get_params: dict={}, response_headers = utils.CaseInsensitiveDict(dict(response.headers)) content_type = response.headers["Content-Type"].split(";", 1)[0] - if soup and content_type in SOUP_CONTENT_TYPES: - soup = bs4.BeautifulSoup(response_content, parser) - return Response(response.status_code, soup, response_headers) + if soup: + if content_type in SOUP_CONTENT_TYPES: + soup = bs4.BeautifulSoup(response_content, parser) + return Response(response.status_code, soup, response_headers) + else: + raise ValueError("Tried to soup non-html/non-xml data") data = response_content.decode(response.encoding or fallback_encoding)