Fix garth token serialization using Pydantic v2 API
All checks were successful
Deploy / deploy (push) Successful in 1m36s

The garth library uses Pydantic dataclasses for OAuth tokens which don't
have a serialize() method. Use model_dump() instead, and fix expires_at
handling since it's an integer timestamp not a datetime object.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-12 16:49:16 +00:00
parent 2408839b8b
commit c8a738d0c4

View File

@@ -10,6 +10,7 @@ Usage:
python3 garmin_auth.py python3 garmin_auth.py
""" """
import json import json
from datetime import datetime
from getpass import getpass from getpass import getpass
try: try:
@@ -26,12 +27,13 @@ password = getpass("Garmin password: ")
garth.login(email, password) garth.login(email, password)
tokens = { tokens = {
"oauth1": garth.client.oauth1_token.serialize(), "oauth1": garth.client.oauth1_token.model_dump(),
"oauth2": garth.client.oauth2_token.serialize(), "oauth2": garth.client.oauth2_token.model_dump(),
"expires_at": garth.client.oauth2_token.expires_at.isoformat() "expires_at": garth.client.oauth2_token.expires_at
} }
print("\n--- Copy everything below this line ---") print("\n--- Copy everything below this line ---")
print(json.dumps(tokens, indent=2)) print(json.dumps(tokens, indent=2))
print("--- Copy everything above this line ---") print("--- Copy everything above this line ---")
print(f"\nTokens expire: {tokens['expires_at']}") expires_dt = datetime.fromtimestamp(tokens['expires_at'])
print(f"\nTokens expire: {expires_dt.isoformat()}")