1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-22 10:42:34 +01:00

fix rate limit handling for OAuth APIs (#368)

This commit is contained in:
Mike Fährmann 2019-08-03 13:43:00 +02:00
parent f687052daf
commit f4bc75e854
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
4 changed files with 5 additions and 4 deletions

View File

@ -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

View File

@ -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

View File

@ -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"])

View File

@ -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)