aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar jesopo2019-09-09 14:59:08 +0100
committerGravatar jesopo2019-09-09 14:59:08 +0100
commitb83f5d9e3058179c2e14773843ad8240e8d29824 (patch)
treea197064bd47dade165b12d5325560c21324e3095 /src
parent'str.split' -> 's.split' (diff)
signature
add flag to disable encoding detection
Diffstat (limited to 'src')
-rw-r--r--src/utils/http.py9
1 files changed, 4 insertions, 5 deletions
diff --git a/src/utils/http.py b/src/utils/http.py
index 46dcc1ae..71cacef6 100644
--- a/src/utils/http.py
+++ b/src/utils/http.py
@@ -86,9 +86,9 @@ def _find_encoding(soup: bs4.BeautifulSoup) -> typing.Optional[str]:
def request(url: str, method: str="GET", get_params: dict={},
post_data: typing.Any=None, headers: dict={},
json_data: typing.Any=None, code: bool=False, json: bool=False,
- soup: bool=False, parser: str="lxml", fallback_encoding: str="utf8",
- allow_redirects: bool=True, check_content_type: bool=True
- ) -> Response:
+ soup: bool=False, parser: str="lxml", detect_encoding: bool=True,
+ fallback_encoding: str="utf8", allow_redirects: bool=True,
+ check_content_type: bool=True) -> Response:
if not urllib.parse.urlparse(url).scheme:
url = "http://%s" % url
@@ -121,9 +121,8 @@ def request(url: str, method: str="GET", get_params: dict={},
response_headers = utils.CaseInsensitiveDict(dict(response.headers))
content_type = response.headers.get("Content-Type", "").split(";", 1)[0]
- souped = None
encoding = response.encoding
- if content_type and content_type in SOUP_CONTENT_TYPES:
+ if detect_encoding and content_type and content_type in SOUP_CONTENT_TYPES:
souped = bs4.BeautifulSoup(response_content, parser)
encoding = _find_encoding(souped) or encoding or "iso-8859-1"