1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-22 18:53:21 +01:00

retry HTTP requests for more exception classes

This commit is contained in:
Mike Fährmann 2018-11-19 12:33:34 +01:00
parent c2e59b9a7d
commit b828473aa3
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
2 changed files with 11 additions and 5 deletions

View File

@ -64,9 +64,12 @@ class Extractor():
while True:
try:
response = self.session.request(method, url, **kwargs)
except (requests.ConnectionError, requests.Timeout) as exc:
except (requests.exceptions.ConnectionError,
requests.exceptions.Timeout,
requests.exceptions.ChunkedEncodingError,
requests.exceptions.ContentDecodingError) as exc:
msg = exc
except requests.exceptions.RequestException as exc:
except (requests.exceptions.RequestException) as exc:
raise exception.HttpError(exc)
else:
code = response.status_code
@ -79,11 +82,11 @@ class Extractor():
if code < 500 and code != 429:
break
self.log.debug("%s (%d/%d)", msg, tries + 1, retries)
tries += 1
self.log.debug("%s (%d/%d)", msg, tries, retries)
if tries >= retries:
break
time.sleep(2 ** tries)
tries += 1
raise exception.HttpError(msg)

View File

@ -60,7 +60,10 @@ class Job():
res = str(exc) or "resource (gallery/image/user)"
log.error("The %s at '%s' does not exist", res, self.url)
except exception.HttpError as exc:
log.error("HTTP request failed: %s", exc)
err = exc.args[0]
if isinstance(err, Exception):
err = "{}: {}".format(err.__class__.__name__, err)
log.error("HTTP request failed: %s", err)
except exception.FormatError as exc:
err, obj = exc.args
log.error("Applying %s format string failed: %s: %s",