[dl:http] add 'sleep-429' option (#6996)
This commit is contained in:
@@ -5564,6 +5564,21 @@ Description
|
|||||||
regardless of this option.
|
regardless of this option.
|
||||||
|
|
||||||
|
|
||||||
|
downloader.http.sleep-429
|
||||||
|
-------------------------
|
||||||
|
Type
|
||||||
|
|Duration|_
|
||||||
|
Default
|
||||||
|
`extractor.*.sleep-429`_
|
||||||
|
Description
|
||||||
|
Number of seconds to sleep when receiving a `429 Too Many Requests`
|
||||||
|
response before `retrying <downloader.*.retries_>`__ the request.
|
||||||
|
|
||||||
|
Note: Requires
|
||||||
|
`retry-codes <downloader.http.retry-codes_>`__
|
||||||
|
to include ``429``.
|
||||||
|
|
||||||
|
|
||||||
downloader.http.validate
|
downloader.http.validate
|
||||||
------------------------
|
------------------------
|
||||||
Type
|
Type
|
||||||
|
|||||||
@@ -918,7 +918,8 @@
|
|||||||
"consume-content" : false,
|
"consume-content" : false,
|
||||||
"enabled" : true,
|
"enabled" : true,
|
||||||
"headers" : null,
|
"headers" : null,
|
||||||
"retry-codes" : [404, 429, 430],
|
"retry-codes" : [],
|
||||||
|
"sleep-429" : 60.0,
|
||||||
"validate" : true
|
"validate" : true
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ class HttpDownloader(DownloaderBase):
|
|||||||
self.verify = self.config("verify", extractor._verify)
|
self.verify = self.config("verify", extractor._verify)
|
||||||
self.mtime = self.config("mtime", True)
|
self.mtime = self.config("mtime", True)
|
||||||
self.rate = self.config("rate")
|
self.rate = self.config("rate")
|
||||||
|
interval_429 = self.config("sleep-429")
|
||||||
|
|
||||||
if not self.config("consume-content", False):
|
if not self.config("consume-content", False):
|
||||||
# this resets the underlying TCP connection, and therefore
|
# this resets the underlying TCP connection, and therefore
|
||||||
@@ -79,6 +80,10 @@ class HttpDownloader(DownloaderBase):
|
|||||||
self.receive = self._receive_rate
|
self.receive = self._receive_rate
|
||||||
if self.progress < 0.0:
|
if self.progress < 0.0:
|
||||||
self.progress = 0.0
|
self.progress = 0.0
|
||||||
|
if interval_429 is None:
|
||||||
|
self.interval_429 = extractor._interval_429
|
||||||
|
else:
|
||||||
|
self.interval_429 = util.build_duration_func(interval_429)
|
||||||
|
|
||||||
def download(self, url, pathfmt):
|
def download(self, url, pathfmt):
|
||||||
try:
|
try:
|
||||||
@@ -93,7 +98,7 @@ class HttpDownloader(DownloaderBase):
|
|||||||
|
|
||||||
def _download_impl(self, url, pathfmt):
|
def _download_impl(self, url, pathfmt):
|
||||||
response = None
|
response = None
|
||||||
tries = 0
|
tries = code = 0
|
||||||
msg = ""
|
msg = ""
|
||||||
|
|
||||||
metadata = self.metadata
|
metadata = self.metadata
|
||||||
@@ -111,10 +116,17 @@ class HttpDownloader(DownloaderBase):
|
|||||||
if response:
|
if response:
|
||||||
self.release_conn(response)
|
self.release_conn(response)
|
||||||
response = None
|
response = None
|
||||||
|
|
||||||
self.log.warning("%s (%s/%s)", msg, tries, self.retries+1)
|
self.log.warning("%s (%s/%s)", msg, tries, self.retries+1)
|
||||||
if tries > self.retries:
|
if tries > self.retries:
|
||||||
return False
|
return False
|
||||||
time.sleep(tries)
|
|
||||||
|
if code == 429 and self.interval_429:
|
||||||
|
s = self.interval_429()
|
||||||
|
time.sleep(s if s > tries else tries)
|
||||||
|
else:
|
||||||
|
time.sleep(tries)
|
||||||
|
code = 0
|
||||||
|
|
||||||
tries += 1
|
tries += 1
|
||||||
file_header = None
|
file_header = None
|
||||||
|
|||||||
Reference in New Issue
Block a user