diff --git a/ring_doorbell/__init__.py b/ring_doorbell/__init__.py index fe37317a..50b181df 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() @@ -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):