Repository navigation
Conversation
Applications such as High Tide store the token's expiry time as text and pass it to load_oauth_session. tidalapi didn't use the value before, but now that requests refresh the access token shortly before it expires, a string made every request fail with AttributeError: 'str' object has no attribute 'tzinfo'. It is now parsed with datetime.fromisoformat, as load_session_from_file does, and ignored if it can't be parsed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collaborator
|
Welcome and thanks for your contribution. FYI I had a separate commit here that removes This essentially means that we use timezone aware datetime, str() would return something like So whether this works depends on how this string was generated. If it was generated using utcnow(), it should be treated as UTC. It will then look something like: Something like this: if isinstance(expiry_time, str):
# Applications often store the expiry time as text
try:
expiry_time = datetime.datetime.fromisoformat(expiry_time)
except ValueError:
log.info("Ignoring invalid expiry_time %r", expiry_time)
expiry_time = None
if expiry_time is not None and expiry_time.tzinfo is None:
# Treat naive datetimes (e.g. from legacy utcnow()) as UTC
expiry_time = expiry_time.replace(tzinfo=datetime.timezone.utc) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since the 0.9.0 changes, every request checks the access token's expiry time before it's sent (
Requests._access_token_expired). Applications that passexpiry_timetoload_oauth_sessionas a string, as they could until now because tidalapi never used it, now getAttributeError: 'str' object has no attribute 'tzinfo'on every request, including thesessionsrequest insideload_oauth_sessionitself.High Tide is one of them: it stores
str(session.expiry_time)in the keyring and passes that back on the next start, so it would stop working with 0.9.0.load_oauth_sessionnow parses a string withdatetime.fromisoformat, asload_session_from_filealready does, and ignores it with a log message if it can't be parsed (e.g."None"). The new offline tests intest_token_refresh.pycoverstr(datetime), anisoformat()string and an invalid string, and fail with thatAttributeErrorwithout the change.🤖 Generated with Claude Code