diff options
author | James Taylor <user234683@users.noreply.github.com> | 2020-10-25 10:50:33 -0700 |
---|---|---|
committer | James Taylor <user234683@users.noreply.github.com> | 2020-10-25 10:54:15 -0700 |
commit | bcaec7b7d3bb6086ec2f6d0726a641e67a524789 (patch) | |
tree | e2259392aa8b4d7ebbd1cd1c6c8d4ca3c57bd4a9 | |
parent | c09fe63d9be3e0c02bf68c78e5b7ac3c2c504f35 (diff) | |
download | yt-local-bcaec7b7d3bb6086ec2f6d0726a641e67a524789.tar.lz yt-local-bcaec7b7d3bb6086ec2f6d0726a641e67a524789.tar.xz yt-local-bcaec7b7d3bb6086ec2f6d0726a641e67a524789.zip |
fetch_url: move content decoding to before 429 check
Content should be decoded before we try reading page to check for
429. Lucky that it worked at all before.
-rw-r--r-- | youtube/util.py | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/youtube/util.py b/youtube/util.py index e468224..8d0f8ca 100644 --- a/youtube/util.py +++ b/youtube/util.py @@ -196,6 +196,9 @@ def fetch_url(url, headers=(), timeout=15, report_text=None, data=None, read_finish = time.time() cleanup_func(response) # release_connection for urllib3 + content = decode_content( + content, + response.getheader('Content-Encoding', default='identity')) if (response.status == 429 and content.startswith(b'<!DOCTYPE') @@ -210,7 +213,6 @@ def fetch_url(url, headers=(), timeout=15, report_text=None, data=None, if report_text: print(report_text, ' Latency:', round(response_time - start_time,3), ' Read time:', round(read_finish - response_time,3)) - content = decode_content(content, response.getheader('Content-Encoding', default='identity')) if settings.debugging_save_responses and debug_name is not None: save_dir = os.path.join(settings.data_dir, 'debug') |