Skip to content

Commit

Permalink
fix rate limit handling for OAuth APIs (#368)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikf committed Aug 3, 2019
1 parent f687052 commit f4bc75e
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion gallery_dl/extractor/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ def request(self, url, method="GET", *, session=None, retries=None,
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
Expand Down
2 changes: 1 addition & 1 deletion gallery_dl/extractor/deviantart.py
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ def _call(self, endpoint, params=None, fatal=True, public=True):

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

Expand Down
2 changes: 1 addition & 1 deletion gallery_dl/extractor/reddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def _call(self, endpoint, params):
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"])
Expand Down
2 changes: 1 addition & 1 deletion gallery_dl/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,6 @@ def __init__(self, extractor):
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)

1 comment on commit f4bc75e

@indrakaw
Copy link

@indrakaw indrakaw commented on f4bc75e Aug 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

Addendum:
Get it tagged already.

Please sign in to comment.