From 4313c95bc94990a4e2362fe9e34060ca133e7809 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Sat, 11 Aug 2018 23:54:25 +0200 Subject: [PATCH] improve error message for OAuth2 authentication --- gallery_dl/extractor/deviantart.py | 7 ++++--- gallery_dl/extractor/reddit.py | 5 +++-- gallery_dl/job.py | 6 +++--- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/gallery_dl/extractor/deviantart.py b/gallery_dl/extractor/deviantart.py index f48870fb..c21fbcc9 100644 --- a/gallery_dl/extractor/deviantart.py +++ b/gallery_dl/extractor/deviantart.py @@ -561,10 +561,11 @@ class DeviantartAPI(): auth = (self.client_id, self.client_secret) response = self.session.post(url, data=data, auth=auth) - if response.status_code != 200: - raise exception.AuthenticationError() - data = response.json() + + if response.status_code != 200: + raise exception.AuthenticationError('"{} ({})"'.format( + data.get("error_description"), data.get("error"))) if refresh_token: _refresh_token_cache.invalidate(refresh_token) _refresh_token_cache(refresh_token, data["refresh_token"]) diff --git a/gallery_dl/extractor/reddit.py b/gallery_dl/extractor/reddit.py index 6794b165..75403b7b 100644 --- a/gallery_dl/extractor/reddit.py +++ b/gallery_dl/extractor/reddit.py @@ -216,7 +216,7 @@ class RedditAPI(): """Actual authenticate implementation""" url = "https://www.reddit.com/api/v1/access_token" if refresh_token: - self.log.info("Refreshing access token") + self.log.info("Refreshing private access token") data = {"grant_type": "refresh_token", "refresh_token": refresh_token} else: @@ -226,7 +226,8 @@ class RedditAPI(): "device_id": "DO_NOT_TRACK_THIS_DEVICE"} response = self.session.post(url, data=data, auth=(self.client_id, "")) if response.status_code != 200: - raise exception.AuthenticationError() + raise exception.AuthenticationError('"{} ({})"'.format( + response.json().get("message"), response.status_code)) return "Bearer " + response.json()["access_token"] def _call(self, endpoint, params): diff --git a/gallery_dl/job.py b/gallery_dl/job.py index cf507581..597ae898 100644 --- a/gallery_dl/job.py +++ b/gallery_dl/job.py @@ -63,9 +63,9 @@ class Job(): log = self.extractor.log for msg in self.extractor: self.dispatch(msg) - except exception.AuthenticationError: - log.error("Authentication failed. Please provide a valid " - "username/password pair.") + except exception.AuthenticationError as exc: + msg = str(exc) or "Please provide a valid username/password pair." + log.error("Authentication failed: %s", msg) except exception.AuthorizationError: log.error("You do not have permission to access the resource " "at '%s'", self.url)