From 1f58206bcba83d5b1f5ff422b4d7729e7589a116 Mon Sep 17 00:00:00 2001 From: Marcelo Moreira de Mello Date: Fri, 3 Nov 2017 12:33:40 -0400 Subject: [PATCH 1/2] Fixed traceback when req.status_code is None --- ring_doorbell/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ring_doorbell/__init__.py b/ring_doorbell/__init__.py index fe37317a..b0fc5a29 100644 --- a/ring_doorbell/__init__.py +++ b/ring_doorbell/__init__.py @@ -77,7 +77,7 @@ def _process_cached_session(self): # if not, it should continue to get a new auth token url = API_URI + DEVICES_ENDPOINT req = self.query(url, raw=True) - if req.status_code == 200: + if req and req.status_code == 200: self._authenticate(session=req) else: self._authenticate() From 2847ba4851c743a410e04531adfce57c7fdb43fd Mon Sep 17 00:00:00 2001 From: Marcelo Moreira de Mello Date: Fri, 3 Nov 2017 12:47:55 -0400 Subject: [PATCH 2/2] Makes lint happy --- ring_doorbell/__init__.py | 7 +++++-- ring_doorbell/utils.py | 16 +++++----------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/ring_doorbell/__init__.py b/ring_doorbell/__init__.py index b0fc5a29..50b181df 100644 --- a/ring_doorbell/__init__.py +++ b/ring_doorbell/__init__.py @@ -99,7 +99,8 @@ def _authenticate(self, attempts=RETRY_TOKEN, session=None): headers=HEADERS) else: req = session - except: + except requests.exceptions.RequestException as err_msg: + _LOGGER.error("Error!! %s", err_msg) raise # if token is expired, refresh credentials and try again @@ -173,7 +174,9 @@ def query(self, if self.debug: _LOGGER.debug("_query %s ret %s", loop, req.status_code) - except: + + except requests.exceptions.RequestException as err_msg: + _LOGGER.error("Error!! %s", err_msg) raise # if token is expired, refresh credentials and try again diff --git a/ring_doorbell/utils.py b/ring_doorbell/utils.py index 0348a771..a5cc2814 100644 --- a/ring_doorbell/utils.py +++ b/ring_doorbell/utils.py @@ -21,11 +21,8 @@ def _locator(lst, key, value): def _clean_cache(filename): """Remove filename if pickle version mismatch.""" - try: - if os.path.isfile(filename): - os.remove(filename) - except: - raise + if os.path.isfile(filename): + os.remove(filename) # initialize cache since file was removed initial_cache_data = CACHE_ATTRS @@ -40,12 +37,9 @@ def _exists_cache(filename): def _save_cache(data, filename): """Dump data into a pickle file.""" - try: - with open(filename, 'wb') as pickle_db: - pickle.dump(data, pickle_db) - return True - except: - raise + with open(filename, 'wb') as pickle_db: + pickle.dump(data, pickle_db) + return True def _read_cache(filename):