Added 429 control
This commit is contained in:
@@ -1340,23 +1340,25 @@ def create_bsky_client(base_url, handle, password):
|
|||||||
normalized_base_url = (base_url or DEFAULT_BSKY_BASE_URL).strip().rstrip("/")
|
normalized_base_url = (base_url or DEFAULT_BSKY_BASE_URL).strip().rstrip("/")
|
||||||
logging.info(f"🔐 Connecting Bluesky client via base URL: {normalized_base_url}")
|
logging.info(f"🔐 Connecting Bluesky client via base URL: {normalized_base_url}")
|
||||||
|
|
||||||
try:
|
client = Client(base_url=normalized_base_url)
|
||||||
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.login(handle, password)
|
max_retries = 3
|
||||||
return client
|
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 ---
|
# --- State Management ---
|
||||||
|
|||||||
Reference in New Issue
Block a user