diff --git a/gallery_dl/extractor/common.py b/gallery_dl/extractor/common.py index d8f7b476..fde7aaf2 100644 --- a/gallery_dl/extractor/common.py +++ b/gallery_dl/extractor/common.py @@ -54,16 +54,17 @@ class Extractor(): return config.interpolate( ("extractor", self.category, self.subcategory, key), default) - def request(self, url, method="GET", *, + def request(self, url, method="GET", *, session=None, encoding=None, expect=(), retries=None, **kwargs): tries = 0 retries = retries or self._retries + session = session or self.session kwargs.setdefault("timeout", self._timeout) kwargs.setdefault("verify", self._verify) while True: try: - response = self.session.request(method, url, **kwargs) + response = session.request(method, url, **kwargs) except (requests.exceptions.ConnectionError, requests.exceptions.Timeout, requests.exceptions.ChunkedEncodingError, diff --git a/gallery_dl/extractor/flickr.py b/gallery_dl/extractor/flickr.py index 7ffb43d7..9de50c74 100644 --- a/gallery_dl/extractor/flickr.py +++ b/gallery_dl/extractor/flickr.py @@ -295,7 +295,6 @@ class FlickrAPI(oauth.OAuth1API): else: self.formats = self.FORMATS self.formats = self.formats[:4] - self.subcategory = extractor.subcategory def favorites_getList(self, user_id): """Returns a list of the user's favorite photos.""" @@ -387,10 +386,10 @@ class FlickrAPI(oauth.OAuth1API): params["nojsoncallback"] = "1" if self.api_key: params["api_key"] = self.api_key - data = self.session.get(self.API_URL, params=params).json() + data = self.request(self.API_URL, params=params).json() if "code" in data: if data["code"] == 1: - raise exception.NotFoundError(self.subcategory) + raise exception.NotFoundError(self.extractor.subcategory) elif data["code"] == 98: raise exception.AuthenticationError(data.get("message")) elif data["code"] == 99: diff --git a/gallery_dl/extractor/smugmug.py b/gallery_dl/extractor/smugmug.py index cec9e80e..53d3760f 100644 --- a/gallery_dl/extractor/smugmug.py +++ b/gallery_dl/extractor/smugmug.py @@ -238,7 +238,7 @@ class SmugmugAPI(oauth.OAuth1API): params["APIKey"] = self.api_key params["_verbosity"] = "1" - response = self.session.get(url, params=params, headers=self.HEADERS) + response = self.request(url, params=params, headers=self.HEADERS) data = response.json() if 200 <= data["Code"] < 400: diff --git a/gallery_dl/extractor/tumblr.py b/gallery_dl/extractor/tumblr.py index 508a6e1c..accacc5f 100644 --- a/gallery_dl/extractor/tumblr.py +++ b/gallery_dl/extractor/tumblr.py @@ -303,7 +303,7 @@ class TumblrAPI(oauth.OAuth1API): url = "https://api.tumblr.com/v2/blog/{}/{}".format( blog, endpoint) - response = self.session.get(url, params=params) + response = self.request(url, params=params) data = response.json() status = data["meta"]["status"] diff --git a/gallery_dl/oauth.py b/gallery_dl/oauth.py index ee66504d..58126aca 100644 --- a/gallery_dl/oauth.py +++ b/gallery_dl/oauth.py @@ -109,6 +109,7 @@ class OAuth1API(): def __init__(self, extractor): self.log = extractor.log + self.extractor = extractor api_key = extractor.config("api-key", self.API_KEY) api_secret = extractor.config("api-secret", self.API_SECRET) @@ -124,3 +125,8 @@ class OAuth1API(): self.log.debug("Using api_key authentication") self.session = extractor.session self.api_key = api_key + + def request(self, url, method="GET", *, expect=range(400, 500), **kwargs): + kwargs["expect"] = expect + kwargs["session"] = self.session + return self.extractor.request(url, method, **kwargs)