Skip to content
Snippets Groups Projects
Commit 0a190650 authored by jkerdreu's avatar jkerdreu
Browse files

Fix try/except for request

git-svn-id: https://redmine.imt-atlantique.fr/svn/xaal/code/Python/trunk@2031 b32b6428-25c9-4566-ad07-03861ab6144f
parent 28f78426
No related branches found
No related tags found
No related merge requests found
......@@ -72,10 +72,9 @@ class GW:
m.update_sensors(attr)
def readweatherstation(self):
try:
netatmo_data = netatmo.API(self.cfg).get_data()
except:
logger.warn("Unable to connect to NA server")
if netatmo_data == None:
logger.warn("Unable to read weatherstation")
return
main_indoor = netatmo_data["devices"][0] # dic
......
......@@ -28,11 +28,15 @@ class API:
response.raise_for_status()
access_token=response.json()["access_token"]
return access_token
except requests.exceptions.HTTPError as error:
except requests.exceptions.RequestException as error:
logger.warn(error.response.status_code, error.response.text)
return None
def get_data(self): #Fonction which get the information from netatmo API by using a token
token=self.get_token()
if token == None:
return None
cfg = self.configfile['config']
params = {
'access_token': token ,
......@@ -43,8 +47,9 @@ class API:
response.raise_for_status()
data = response.json()["body"]
return data
except requests.exceptions.HTTPError as error:
except requests.exceptions.RequestException as error:
logger.error(error.response.status_code, error.response.text)
return None
class NAModule(object): # NWS: netatmo weather station
......@@ -154,10 +159,9 @@ class ConfigParser: # netatmo weather station config
self.cfg['devices'].inline_comments[k]='This device is removed !!!'
def get_modules(self):
try:
data = data=API(self.cfg).get_data()
except:
logger.warn("Unable to connect to NA server")
if data == None:
logger.warning('Unable to fetch module list')
return None
# NAMain is the first devices
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment