aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Taylor <user234683@users.noreply.github.com>2021-02-25 19:27:28 -0800
committerJesús <heckyel@hyperbola.info>2021-02-26 11:48:38 -0500
commitd604a007a91c9e79206495a406499370082e0b62 (patch)
tree3df450faa55f081ee43f12f28d6e34dfc8596ff9
parent07f14343c4ed7c752885dbca624628af7043d037 (diff)
downloadyt-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>
-rw-r--r--youtube/util.py17
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