diff --git a/skpy/conn.py b/skpy/conn.py index ea8b8a9..b580c4e 100644 --- a/skpy/conn.py +++ b/skpy/conn.py @@ -118,7 +118,7 @@ def externalCall(cls, method, url, codes=(200, 201, 204, 207), **kwargs): print(pformat(dict(resp.headers))) try: print(pformat(resp.json())) - except: + except ValueError: print(resp.text) if resp.status_code not in codes: raise SkypeApiException("{0} response from {1} {2}".format(resp.status_code, method, url), resp) @@ -211,7 +211,7 @@ def __call__(self, method, url, codes=(200, 201, 202, 204, 207), auth=None, head print(pformat(dict(resp.headers))) try: print(pformat(resp.json())) - except: + except ValueError: print(resp.text) if resp.status_code not in codes: if resp.status_code == 429: @@ -243,7 +243,7 @@ def syncStateCall(self, method, url, params={}, **kwargs): resp = self(method, url, params=params, **kwargs) try: json = resp.json() - except: + except ValueError: # Don't do anything if not a JSON response. pass else: @@ -286,13 +286,16 @@ def readToken(self): """ if not self.tokenFile: raise SkypeAuthException("No token file specified") - with open(self.tokenFile, "r") as f: - lines = f.read().splitlines() + try: + with open(self.tokenFile, "r") as f: + lines = f.read().splitlines() + except OSError: + raise SkypeAuthException("Token file doesn't exist or not readable") try: user, skypeToken, skypeExpiry, regToken, regExpiry, msgsHost = lines skypeExpiry = datetime.fromtimestamp(int(skypeExpiry)) regExpiry = datetime.fromtimestamp(int(regExpiry)) - except: + except ValueError: raise SkypeAuthException("Token file is malformed") if datetime.now() >= skypeExpiry: raise SkypeAuthException("Token file has expired") diff --git a/skpy/main.py b/skpy/main.py index d375790..b579746 100644 --- a/skpy/main.py +++ b/skpy/main.py @@ -2,7 +2,7 @@ import requests -from .core import SkypeObj, SkypeEnum +from .core import SkypeObj, SkypeEnum, SkypeAuthException from .util import SkypeUtils from .conn import SkypeConnection from .user import SkypeUser, SkypeContact, SkypeContacts @@ -65,7 +65,7 @@ def __init__(self, user=None, pwd=None, tokenFile=None, connect=True): if connect and ((user and pwd) or tokenFile): try: self.conn.readToken() - except: + except SkypeAuthException: self.conn.getSkypeToken() self.contacts = SkypeContacts(self) self.chats = SkypeChats(self)