aboutsummaryrefslogtreecommitdiffstats
path: root/youtube/util.py
diff options
context:
space:
mode:
authorJames Taylor <user234683@users.noreply.github.com>2020-02-18 11:47:23 -0800
committerJames Taylor <user234683@users.noreply.github.com>2020-02-18 11:47:23 -0800
commitf25324794916dc51367e399b923e367854e5b5ee (patch)
tree5e248f912ae3131a526da9d122956dc8a7803072 /youtube/util.py
parent8c2b81094ec277865f613aacfa6626bf271a4ab8 (diff)
downloadyt-local-f25324794916dc51367e399b923e367854e5b5ee.tar.lz
yt-local-f25324794916dc51367e399b923e367854e5b5ee.tar.xz
yt-local-f25324794916dc51367e399b923e367854e5b5ee.zip
Fix MaxRetryError when checking for video URL access
The default urllib3 max redirect amount was set to 3. Change it to 10 and do not fail if there is a problem with checking for URL access. Just print the error to the console and proceed. Also add an unrelated remark about the bcptr=9999999999 parameter in watch.py
Diffstat (limited to 'youtube/util.py')
-rw-r--r--youtube/util.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/youtube/util.py b/youtube/util.py
index a5bd874..c7168a8 100644
--- a/youtube/util.py
+++ b/youtube/util.py
@@ -195,10 +195,18 @@ def fetch_url(url, headers=(), timeout=15, report_text=None, data=None, cookieja
return content, response
return content
-def head(url, use_tor=False, report_text=None):
+def head(url, use_tor=False, report_text=None, max_redirects=10):
pool = get_pool(use_tor and settings.route_tor)
start_time = time.time()
- response = pool.request('HEAD', url)
+
+ # default: Retry.DEFAULT = Retry(3)
+ # (in connectionpool.py in urllib3)
+ # According to the documentation for urlopen, a redirect counts as a retry
+ # by default. So there are 3 redirects max by default. Let's change that
+ # to 10 since googlevideo redirects a lot.
+ retries = urllib3.Retry(3+max_redirects, redirect=max_redirects,
+ raise_on_redirect=False)
+ response = pool.request('HEAD', url, retries=retries)
if report_text:
print(report_text, ' Latency:', round(time.time() - start_time,3))
return response