diff --git a/gpapi/config.py b/gpapi/config.py index ea1a6f2..f31c103 100644 --- a/gpapi/config.py +++ b/gpapi/config.py @@ -29,6 +29,13 @@ config.read(filepath) +class InvalidLocaleError(Exception): + pass + +class InvalidTimezoneError(Exception): + pass + + def getDevicesCodenames(): """Returns a list containing devices codenames""" return config.sections() @@ -51,19 +58,19 @@ def __init__(self, device): def set_locale(self, locale): # test if provided locale is valid if locale is None or type(locale) is not str: - raise Exception('Wrong locale supplied') + raise InvalidLocaleError() # check if locale matches the structure of a common # value like "en_US" if match(r'[a-z]{2}\_[A-Z]{2}', locale) is None: - raise Exception('Wrong locale supplied') + raise InvalidLocaleError() self.locale = locale def set_timezone(self, timezone): if timezone is None or type(timezone) is not str: timezone = self.device.get('timezone') if timezone is None: - raise Exception('Wrong timezone supplied') + raise InvalidTimezoneError() self.timezone = timezone def getBaseHeaders(self): diff --git a/gpapi/googleplay.py b/gpapi/googleplay.py index 3c8fd9c..3882c84 100644 --- a/gpapi/googleplay.py +++ b/gpapi/googleplay.py @@ -53,6 +53,9 @@ def __init__(self, value): def __str__(self): return repr(self.value) +class SecurityCheckError(Exception): + pass + class GooglePlayAPI(object): """Google Play Unofficial API Class @@ -217,9 +220,7 @@ def login(self, email=None, password=None, gsfId=None, authSubToken=None): ac2dmToken = params["auth"] elif "error" in params: if "NeedsBrowser" in params["error"]: - raise LoginError("Security check is needed, try to visit " - "https://accounts.google.com/b/0/DisplayUnlockCaptcha " - "to unlock, or setup an app-specific password") + raise SecurityCheckError() raise LoginError("server says: " + params["error"]) else: raise LoginError("Auth token not found.")