Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is_token_expired buggy on non-UTC system #892

Open
joeb1415 opened this issue Nov 23, 2022 · 1 comment
Open

is_token_expired buggy on non-UTC system #892

joeb1415 opened this issue Nov 23, 2022 · 1 comment
Labels

Comments

@joeb1415
Copy link

Describe the bug
is_token_expired() uses time.time() which returns system local time, which, when running on a non-UTC system, can return incorrectly.

Your code

token_info = auth_manager.cache_handler.get_cached_token()

print(f"Token expires_at:     {token_info['expires_at']}")
print(f"Local Time (Pacific): {int(time.time())}")
print(f"UTC Time:             {int(time.mktime(time.gmtime()))}")

# Token shows not expired, but it is expected that it is expired
print(auth_manager.is_token_expired(token_info))
Token expires_at:     1669239147
Local Time (Pacific): 1669229727
UTC Time:             1669247727
False

Expected behavior
Replace time.time() with, e.g., time.mktime(time.gmtime()) wherever used.

Environment:

  • OS: Mac
  • Python version: 3.6.8
  • spotipy version: 2.21.0
  • IDE: VSCode

Additional context
Add any other context about the problem here.

@joeb1415 joeb1415 added the bug label Nov 23, 2022
@stephanebruckert
Copy link
Member

Great catch, would love a PR for it if you get a chance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants