diff --git a/twitter2bsky_daemon.py b/twitter2bsky_daemon.py index 3f2fd1a..37b1f49 100644 --- a/twitter2bsky_daemon.py +++ b/twitter2bsky_daemon.py @@ -1340,23 +1340,25 @@ def create_bsky_client(base_url, handle, password): normalized_base_url = (base_url or DEFAULT_BSKY_BASE_URL).strip().rstrip("/") logging.info(f"🔐 Connecting Bluesky client via base URL: {normalized_base_url}") - try: - client = Client(base_url=normalized_base_url) - except TypeError: - logging.warning( - "⚠️ Your atproto Client does not accept base_url in constructor. Falling back." - ) - client = Client() - try: - if hasattr(client, "base_url"): - client.base_url = normalized_base_url - elif hasattr(client, "_base_url"): - client._base_url = normalized_base_url - except Exception as e: - logging.warning(f"⚠️ Could not apply custom base URL cleanly: {e}") + client = Client(base_url=normalized_base_url) - client.login(handle, password) - return client + max_retries = 3 + for attempt in range(1, max_retries + 1): + try: + client.login(handle, password) + return client + except Exception as e: + msg = str(e) + is_rate = ("429" in msg) or ("RateLimitExceeded" in msg) + if is_rate and attempt < max_retries: + wait = get_rate_limit_wait_seconds(e, default_delay=60) + logging.warning( + f"⏳ Login rate-limited (attempt {attempt}/{max_retries}). " + f"Sleeping {wait}s before retry." + ) + time.sleep(wait) + continue + raise # --- State Management ---