From d604a007a91c9e79206495a406499370082e0b62 Mon Sep 17 00:00:00 2001 From: James Taylor Date: Thu, 25 Feb 2021 19:27:28 -0800 Subject: Debugging response saving: save page even if it's an HTTP error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This will help debug new types of exit node blockage or other errors. Signed-off-by: Jesús --- youtube/util.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'youtube') 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 -- cgit v1.2.3