Skip to content

Commit

Permalink
Rename allow_retry to allow_token_refresh
Browse files Browse the repository at this point in the history
Because I need to use allow_retry for #18
  • Loading branch information
simonw committed Feb 19, 2022
1 parent 0ad0d47 commit a78460c
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions google_drive_to_sqlite/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,25 +88,25 @@ def get_access_token(self, force_refresh=False):
self.access_token = data["access_token"]
return self.access_token

def get(self, url, params=None, headers=None, allow_retry=True):
def get(self, url, params=None, headers=None, allow_token_refresh=True):
headers = headers or {}
headers["Authorization"] = "Bearer {}".format(self.get_access_token())
self.log("GET: {} {}".format(url, params))
response = httpx.get(url, params=params, headers=headers, timeout=self.timeout)
if response.status_code == 401 and allow_retry:
if response.status_code == 401 and allow_token_refresh:
# Try again after refreshing the token
self.get_access_token(force_refresh=True)
return self.get(url, params, headers, allow_retry=False)
return self.get(url, params, headers, allow_token_refresh=False)
return response

def post(self, url, data=None, headers=None, allow_retry=True):
def post(self, url, data=None, headers=None, allow_token_refresh=True):
headers = headers or {}
headers["Authorization"] = "Bearer {}".format(self.get_access_token())
self.log("POST: {}".format(url))
response = httpx.post(url, data=data, headers=headers, timeout=self.timeout)
if response.status_code == 403 and allow_retry:
if response.status_code == 403 and allow_token_refresh:
self.get_access_token(force_refresh=True)
return self.post(url, data, headers, allow_retry=False)
return self.post(url, data, headers, allow_token_refresh=False)
return response

@contextmanager
Expand Down

0 comments on commit a78460c

Please sign in to comment.