diff options
author | James Taylor <user234683@users.noreply.github.com> | 2021-02-25 19:27:28 -0800 |
---|---|---|
committer | Jesús <heckyel@hyperbola.info> | 2021-02-26 11:48:38 -0500 |
commit | d604a007a91c9e79206495a406499370082e0b62 (patch) | |
tree | 3df450faa55f081ee43f12f28d6e34dfc8596ff9 /youtube/util.py | |
parent | 07f14343c4ed7c752885dbca624628af7043d037 (diff) | |
download | yt-local-d604a007a91c9e79206495a406499370082e0b62.tar.lz yt-local-d604a007a91c9e79206495a406499370082e0b62.tar.xz yt-local-d604a007a91c9e79206495a406499370082e0b62.zip |
Debugging response saving: save page even if it's an HTTP error
This will help debug new types of exit node blockage or other
errors.
Signed-off-by: Jesús <heckyel@hyperbola.info>
Diffstat (limited to 'youtube/util.py')
-rw-r--r-- | youtube/util.py | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/youtube/util.py b/youtube/util.py index 701d922..f8c4be5 100644 --- a/youtube/util.py +++ b/youtube/util.py @@ -292,6 +292,15 @@ def fetch_url(url, headers=(), timeout=15, report_text=None, data=None, content, response.getheader('Content-Encoding', default='identity')) + if (settings.debugging_save_responses + and debug_name is not None and content): + save_dir = os.path.join(settings.data_dir, 'debug') + if not os.path.exists(save_dir): + os.makedirs(save_dir) + + with open(os.path.join(save_dir, debug_name), 'wb') as f: + f.write(content) + if response.status == 429: ip = re.search( br'IP address: ((?:[\da-f]*:)+[\da-f]+|(?:\d+\.)+\d+)', @@ -321,14 +330,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)) - if settings.debugging_save_responses and debug_name is not None: - save_dir = os.path.join(settings.data_dir, 'debug') - if not os.path.exists(save_dir): - os.makedirs(save_dir) - - with open(os.path.join(save_dir, debug_name), 'wb') as f: - f.write(content) - return content |