Skip to content

is_token_expired buggy on non-UTC system #892

@joeb1415

Description

@joeb1415

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions