From f4bc75e85487c26a01ce9b7fd0bb8f228d1fb46c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Sat, 3 Aug 2019 13:43:00 +0200 Subject: [PATCH] fix rate limit handling for OAuth APIs (#368) --- gallery_dl/extractor/common.py | 3 ++- gallery_dl/extractor/deviantart.py | 2 +- gallery_dl/extractor/reddit.py | 2 +- gallery_dl/oauth.py | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/gallery_dl/extractor/common.py b/gallery_dl/extractor/common.py index 5c40e2a5..a90af1c4 100644 --- a/gallery_dl/extractor/common.py +++ b/gallery_dl/extractor/common.py @@ -87,7 +87,8 @@ class Extractor(): raise exception.HttpError(exc) else: code = response.status_code - if 200 <= code < 400 or not fatal and \ + if 200 <= code < 400 or fatal is None and \ + (400 <= code < 500) or not fatal and \ (400 <= code < 429 or 431 <= code < 500): if encoding: response.encoding = encoding diff --git a/gallery_dl/extractor/deviantart.py b/gallery_dl/extractor/deviantart.py index eed2f3e4..a04f7ba7 100644 --- a/gallery_dl/extractor/deviantart.py +++ b/gallery_dl/extractor/deviantart.py @@ -817,7 +817,7 @@ class DeviantartAPI(): self.authenticate(None if public else self.refresh_token) response = self.extractor.request( - url, headers=self.headers, params=params, fatal=False) + url, headers=self.headers, params=params, fatal=None) data = response.json() status = response.status_code diff --git a/gallery_dl/extractor/reddit.py b/gallery_dl/extractor/reddit.py index 2ba4b99a..94e95e85 100644 --- a/gallery_dl/extractor/reddit.py +++ b/gallery_dl/extractor/reddit.py @@ -234,7 +234,7 @@ class RedditAPI(): url = "https://oauth.reddit.com" + endpoint params["raw_json"] = 1 self.authenticate() - response = self.extractor.request(url, params=params, fatal=False) + response = self.extractor.request(url, params=params, fatal=None) remaining = response.headers.get("x-ratelimit-remaining") if remaining and float(remaining) < 2: wait = int(response.headers["x-ratelimit-reset"]) diff --git a/gallery_dl/oauth.py b/gallery_dl/oauth.py index 8a12755e..69ab4f61 100644 --- a/gallery_dl/oauth.py +++ b/gallery_dl/oauth.py @@ -127,6 +127,6 @@ class OAuth1API(): self.api_key = api_key def request(self, url, method="GET", **kwargs): - kwargs["fatal"] = False + kwargs["fatal"] = None kwargs["session"] = self.session return self.extractor.request(url, method, **kwargs)