Skip to content

Commit

Permalink
add retry if the http connection fails (e.g. expired token)
Browse files Browse the repository at this point in the history
  • Loading branch information
ebiiii committed Oct 4, 2016
1 parent dc736ad commit 4328400
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions gsn/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,14 @@ def get_latest_values(self, vs_name=None):
assert vs_name is not None
if self.expiration <= time.time():
self.refresh_token()
data = self.client.request("/sensors/{}?latestValues=True".format(vs_name))
try:
data = self.client.request("/sensors/{}?latestValues=True".format(vs_name))
except:
self.refresh_token()
try:
data = self.client.request("/sensors/{}?latestValues=True".format(vs_name))
except:
return None
return Sensor(geojson_object=data)

def push_values(self, sensor_data=None):
Expand All @@ -67,6 +74,12 @@ def push_values(self, sensor_data=None):
res = self.client.request("/sensors/{}/data".format(sensor_data.name),
data=sensor_data.to_geojson().encode('utf_8'),
headers={'Content-type': 'application/json'})
except HTTPError as e:
return e.readlines()
except:
self.refresh_token()
try:
res = self.client.request("/sensors/{}/data".format(sensor_data.name),
data=sensor_data.to_geojson().encode('utf_8'),
headers={'Content-type': 'application/json'})
except HTTPError as e:
return e.readlines()
return res

0 comments on commit 4328400

Please sign in to comment.