Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions gplaycli/gplaycli.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def __init__(self, args=None, config_file=None):

self.api = None
self.token_passed = False
self.token_attempts = 0


config = configparser.ConfigParser()
Expand Down Expand Up @@ -343,7 +344,7 @@ def search(self, search_string, free_only=True, include_headers=True):
"""
try:
results = self.api.search(search_string)
except IndexError:
except (IndexError, RequestError):
results = []
if not results:
logger.info("No result")
Expand Down Expand Up @@ -424,11 +425,17 @@ def connect_token(self):
else:
logger.info("Using auto retrieved token to connect to API")
try:
self.token_attempts += 1
self.api.login(authSubToken=self.token, gsfId=int(self.gsfid, 16))
except (ValueError, IndexError, LoginError, DecodeError, SystemError, RequestError):
logger.info("Token has expired or is invalid. Retrieving a new one...")
self.retrieve_token(force_new=True)
self.connect()
if self.token_attempts < 5:
logger.info("Token has expired or is invalid. Retrieving a new one...")
self.retrieve_token(force_new=True)
self.connect()
else:
logger.error("Multiple attempts to fetch anonymous token failed.")
logger.error("Try setting 'token=False' and adding Google credentials to gplaycli.conf")

return True, None

def connect_credentials(self):
Expand Down