This commit is contained in:
mirage 2023-01-21 17:36:18 +00:00 committed by GitHub
commit 8a1f4fdbf5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 1 deletions

View file

@ -41,6 +41,7 @@ from .compat import (
compat_urllib_error,
compat_urllib_request,
compat_urllib_request_DataHandler,
Forbidden403
)
from .utils import (
age_restricted,
@ -825,6 +826,10 @@ class YoutubeDL(object):
self.report_error(compat_str(e), e.format_traceback())
except MaxDownloadsReached:
raise
except Forbidden403:
# Lets not abuse of this 😜 we don't want to get brutal on the server
time.sleep(random.randint(3, 13))
wrapper(self, *args, **kwargs)
except Exception as e:
if self.params.get('ignoreerrors', False):
self.report_error(error_to_compat_str(e), tb=encode_compat_str(traceback.format_exc()))

View file

@ -3094,6 +3094,11 @@ else:
return ctypes.WINFUNCTYPE(*args, **kwargs)
# Implement an error for which it is raise when error code 403 HTTPError
class Forbidden403(Exception):
pass
__all__ = [
'compat_HTMLParseError',
'compat_HTMLParser',

View file

@ -11,6 +11,7 @@ from .common import FileDownloader
from ..compat import (
compat_str,
compat_urllib_error,
Forbidden403
)
from ..utils import (
ContentTooShortError,
@ -183,9 +184,11 @@ class HttpFD(FileDownloader):
ctx.resume_len = 0
ctx.open_mode = 'wb'
return
elif err.code < 500 or err.code >= 600:
elif err.code != 403 and (err.code < 500 or err.code >= 600):
# Unexpected HTTP error
raise
elif err.code == 403: # The famous 403 Forbidden error
raise Forbidden403
raise RetryDownload(err)
except socket.error as err:
if err.errno != errno.ECONNRESET: