Skip to content

Commit

Permalink
Fix Google Photos expired token mishandling
Browse files Browse the repository at this point in the history
  • Loading branch information
jim-easterbrook committed Sep 17, 2024
1 parent 8cb8285 commit a13c588
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/photini/googlephotos.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import os
import urllib

import keyring
from oauthlib.oauth2.rfc6749.errors import InvalidGrantError
import requests
from requests_oauthlib import OAuth2Session

Expand Down Expand Up @@ -52,10 +54,17 @@ def save_token(self, token):

def api_call(self, url, post=False, **params):
self.open_connection()
if post:
rsp = self.api.post(url, timeout=5, **params)
else:
rsp = self.api.get(url, timeout=5, **params)
try:
if post:
rsp = self.api.post(url, timeout=5, **params)
else:
rsp = self.api.get(url, timeout=5, **params)
except InvalidGrantError as ex:
# probably an expired token, force new login
self.close_connection()
if keyring.get_password('photini', 'googlephotos'):
keyring.delete_password('photini', 'googlephotos')
return {}
rsp = self.check_response(rsp)
if not rsp:
self.close_connection()
Expand Down Expand Up @@ -139,7 +148,10 @@ def on_connect(self, widgets):
rsp = session.api_call(session.oauth_url + 'v2/userinfo')
if not rsp:
yield 'connected', False
self.user_data['lang'] = rsp['locale']
if 'locale' in rsp:
self.user_data['lang'] = rsp['locale']
else:
self.user_data['lang'] = None
name = rsp['name']
rsp = session.check_response(
session.api.get(rsp['picture']), decode=False)
Expand Down

0 comments on commit a13c588

Please sign in to comment.