diff options
| author | 2019-05-28 10:22:35 +0100 | |
|---|---|---|
| committer | 2019-05-28 10:22:35 +0100 | |
| commit | 0be904666923da9e3011559b75345e578b9b956c (patch) | |
| tree | 5ccdc5c47e39e8de3dc889a21deb0934aabed9ae /src | |
| parent | re.escape nicknames for highlight prevention (diff) | |
| signature | ||
Pass str object to BeautifulSoup, not bytes. closes #56
Diffstat (limited to 'src')
| -rw-r--r-- | src/utils/http.py | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/src/utils/http.py b/src/utils/http.py index 0488b0af..2d7c512a 100644 --- a/src/utils/http.py +++ b/src/utils/http.py @@ -64,18 +64,17 @@ def request(url: str, method: str="GET", get_params: dict={}, signal.signal(signal.SIGALRM, signal.SIG_IGN) response_headers = utils.CaseInsensitiveDict(dict(response.headers)) - + data = response_content.decode(response.encoding or fallback_encoding) content_type = response.headers["Content-Type"].split(";", 1)[0] + if soup: if content_type in SOUP_CONTENT_TYPES: - soup = bs4.BeautifulSoup(response_content, parser) + soup = bs4.BeautifulSoup(data, parser) return Response(response.status_code, soup, response_headers) else: raise HTTPWrongContentTypeException( "Tried to soup non-html/non-xml data") - - data = response_content.decode(response.encoding or fallback_encoding) if json and data: try: return Response(response.status_code, _json.loads(data), |
