Skip to content

Commit c1f8a9a

Browse files
feat: add 30-45s random delay before portal credential POST
Garmin's Cloudflare WAF rate-limits requests that go directly from the SSO page GET to the login POST without intervening activity. A random 30-45s delay mimics natural browser behavior and helps avoid the 429 block. Adapted from upstream PR cyberjunky#346. The delay only applies to the portal+cffi / portal+requests fallback strategies. The widget+cffi primary strategy uses a different (HTML form, no clientId) endpoint that is not subject to per-clientId rate limiting and does not need this delay.
1 parent f2f403b commit c1f8a9a

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

garminconnect/client.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
import contextlib
55
import json
66
import logging
7+
import random
78
import re
9+
import time
810
from pathlib import Path
911
from typing import Any
1012

@@ -511,6 +513,14 @@ def _portal_web_login(
511513
timeout=30,
512514
)
513515

516+
# Garmin's Cloudflare WAF rate-limits requests that go directly from
517+
# the SSO page GET to the login POST without intervening activity.
518+
# A random 30-45s delay mimics natural browser behavior and
519+
# consistently avoids the 429 block. (Adapted from upstream PR #346.)
520+
delay_s = random.uniform(30, 45)
521+
_LOGGER.debug("Portal login: sleeping %.1fs before credential POST", delay_s)
522+
time.sleep(delay_s)
523+
514524
# Step 2: POST credentials to the portal login API
515525
login_url = f"{self._sso}/portal/api/login"
516526
login_params = {

0 commit comments

Comments
 (0)