From 79bd7d4122077bbd5fd9721b7c528596664bdf97 Mon Sep 17 00:00:00 2001 From: Alexander Cecile <35971201+AlexanderCecile@users.noreply.github.com> Date: Tue, 18 Aug 2020 19:36:47 -0400 Subject: [PATCH] Tell requests to detect encoding. Changed the get_file_by_url function to infer/guess the encoding of the content we receive. --- updateHostsFile.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/updateHostsFile.py b/updateHostsFile.py index 3e2b00185..b8d64a29c 100644 --- a/updateHostsFile.py +++ b/updateHostsFile.py @@ -1467,7 +1467,9 @@ def maybe_copy_example_file(file_path): def get_file_by_url(url, params, **kwargs): - return requests.get(url=url, params=params, **kwargs).text + req = requests.get(url=url, params=params, **kwargs) + req.encoding = req.apparent_encoding + return req.text def write_data(f, data):