diff --git a/collect.py b/collect.py index 0f015a3..4d28476 100644 --- a/collect.py +++ b/collect.py @@ -53,6 +53,7 @@ from datetime import datetime, timezone from pathlib import Path from server import log_config, network, we_connect +from weconnect.errors import AuthentificationError from server.data_model import ALL_DOMAINS, collect_snapshot, apply_procedural from server.storage_helpers import auto_out_path, load_last_24h_records, load_store, save_store from utils.jay_diff import jay_diff_full @@ -145,6 +146,12 @@ def run(args: argparse.Namespace) -> None: log.info("Record #%d saved at %s", len(store["records"]), snapshot["ts"]) except KeyboardInterrupt: raise + except AuthentificationError: + log.warning("Authentication error — re-logging in before next interval") + try: + wc.login() + except Exception: + log.exception("Re-login failed") except Exception: log.exception("Collection failed — will retry at next interval")