Skip to content

Commit

Permalink
Remove bare excepts
Browse files Browse the repository at this point in the history
  • Loading branch information
Terrance committed Jul 11, 2018
1 parent d8bbba0 commit 029d768
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
15 changes: 9 additions & 6 deletions skpy/conn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions skpy/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 029d768

Please sign in to comment.