From 92528fe0387dddaf19ba562fe98bf073c8a756c9 Mon Sep 17 00:00:00 2001 From: neodarz Date: Sun, 12 Apr 2020 08:54:50 +0200 Subject: Re ask token if scope is invalid --- pyfunkwhale/client.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/pyfunkwhale/client.py b/pyfunkwhale/client.py index c905c57..1fce019 100644 --- a/pyfunkwhale/client.py +++ b/pyfunkwhale/client.py @@ -5,6 +5,7 @@ import json import re from time import time from requests_oauthlib import OAuth2Session +from oauthlib.oauth2.rfc6749.errors import InvalidScopeError from requests.models import Response from pyfunkwhale.utils import read_file, write_file @@ -65,11 +66,14 @@ class Client(object): token from the instance. """ if time() - 60 > self.token["expires_at"]: - self.token = self.oauth_client.refresh_token( - self.token_endpoint, - refresh_token=self.token["refresh_token"], - client_id=self.client_id, - client_secret=self.client_secret) + try: + self.token = self.oauth_client.refresh_token( + self.token_endpoint, + refresh_token=self.token["refresh_token"], + client_id=self.client_id, + client_secret=self.client_secret) + except InvalidScopeError: + self._get_token() write_file(self.token_filename, self.token) def call(self, endpoint: str, method: str, params: dict = None, -- cgit v1.2.1