From c8a738d0c4c74ae8a856fc2dff19d1b8553dfc90 Mon Sep 17 00:00:00 2001 From: Petru Paler Date: Mon, 12 Jan 2026 16:49:16 +0000 Subject: [PATCH] Fix garth token serialization using Pydantic v2 API 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 --- scripts/garmin_auth.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/scripts/garmin_auth.py b/scripts/garmin_auth.py index fd0fcf8..8a64ac5 100644 --- a/scripts/garmin_auth.py +++ b/scripts/garmin_auth.py @@ -10,6 +10,7 @@ Usage: python3 garmin_auth.py """ import json +from datetime import datetime from getpass import getpass try: @@ -26,12 +27,13 @@ password = getpass("Garmin password: ") garth.login(email, password) tokens = { - "oauth1": garth.client.oauth1_token.serialize(), - "oauth2": garth.client.oauth2_token.serialize(), - "expires_at": garth.client.oauth2_token.expires_at.isoformat() + "oauth1": garth.client.oauth1_token.model_dump(), + "oauth2": garth.client.oauth2_token.model_dump(), + "expires_at": garth.client.oauth2_token.expires_at } print("\n--- Copy everything below this line ---") print(json.dumps(tokens, indent=2)) 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()}")