Skip to content

Commit 03a6e36

Browse files
authored
Merge pull request #97 from tchellomello/hass_oauth_token_expired
Fixes when oauth tokens expired and fetches a new token.
2 parents f791e25 + 954017c commit 03a6e36

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

fitbit/api.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from urllib import urlencode
1111

1212
from requests_oauthlib import OAuth2, OAuth2Session
13+
from oauthlib.oauth2.rfc6749.errors import TokenExpiredError
1314
from fitbit.exceptions import (BadResponse, DeleteError, HTTPBadRequest,
1415
HTTPUnauthorized, HTTPForbidden,
1516
HTTPServerError, HTTPConflict, HTTPNotFound,
@@ -66,7 +67,7 @@ def make_request(self, url, data={}, method=None, **kwargs):
6667
try:
6768
auth = OAuth2(client_id=self.client_id, token=self.token)
6869
response = self._request(method, url, data=data, auth=auth, **kwargs)
69-
except HTTPUnauthorized as e:
70+
except (HTTPUnauthorized, TokenExpiredError) as e:
7071
self.refresh_token()
7172
auth = OAuth2(client_id=self.client_id, token=self.token)
7273
response = self._request(method, url, data=data, auth=auth, **kwargs)

0 commit comments

Comments
 (0)