Skip to content

Commit b6db1a0

Browse files
tehmufifnmanlockwooddev
authored andcommitted
Added leeway protection against expired tokens. (#13)
1 parent 3d0928f commit b6db1a0

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,7 @@
3030
## 2.3.0 (06-05-2019)
3131

3232
* Add profile api
33+
34+
## 2.3.1 (20-05-2019)
35+
36+
* Added some leeway protection against expired tokens

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from setuptools import setup, find_packages
44

55

6-
__version__ = '2.3.0'
6+
__version__ = '2.3.1'
77

88

99
def read(*parts):

wowapi/api.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,11 @@ def get_resource(self, resource, region, *args, **filters):
121121
logger.info('Fetching access token..')
122122
self._get_client_credentials(region)
123123
else:
124-
now = datetime.utcnow()
125-
# refresh access token if expired
126-
if now >= self._access_tokens[region]['expiration']:
124+
now = self._utcnow()
125+
# refresh access token if expiring in the next 30 seconds.
126+
# this protects against the rare occurrence of hitting
127+
# the API right as your token expires, causing errors.
128+
if now >= self._access_tokens[region]['expiration'] - timedelta(seconds=30):
127129
logger.info('Access token expired. Fetching new token..')
128130
self._get_client_credentials(region)
129131

0 commit comments

Comments
 (0)