From 06c7091bb3a5d69f3fd00814f82528f43d677686 Mon Sep 17 00:00:00 2001 From: Bobby Date: Wed, 25 Nov 2026 15:06:40 -0500 Subject: [PATCH] task: set User-Agent on claim (Cloudflare 1010), show error bodies Co-Authored-By: Claude Opus 5.5 --- docs/research/simplefin-66/probe.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/docs/research/simplefin-66/probe.py b/docs/research/simplefin-66/probe.py index 8ead7d6..e7f5ea6 100644 --- a/docs/research/simplefin-66/probe.py +++ b/docs/research/simplefin-66/probe.py @@ -37,6 +37,8 @@ from pathlib import Path STATE = Path.home() / ".local/state/hapi-simplefin-probe" DAY = 86400 +# Cloudflare in front of SimpleFIN rejects Python-urllib's default UA (error 1010). +UA = "hapi-simplefin-probe/1" def die(msg: str) -> None: @@ -91,12 +93,12 @@ def get_accounts(url: str, **params: str) -> dict: base = urllib.parse.urlunsplit((u.scheme, netloc, u.path.rstrip("/") + "/accounts", "", "")) full = base + ("?" + urllib.parse.urlencode(params) if params else "") cred = base64.b64encode(f"{urllib.parse.unquote(u.username)}:{urllib.parse.unquote(u.password)}".encode()).decode() - req = urllib.request.Request(full, headers={"Authorization": f"Basic {cred}", "User-Agent": "simplefin-probe"}) + req = urllib.request.Request(full, headers={"Authorization": f"Basic {cred}", "User-Agent": UA}) try: with urllib.request.urlopen(req, timeout=120) as r: return json.load(r) except urllib.error.HTTPError as e: - die(f"HTTP {e.code} from /accounts (params {sorted(params)})") + die(f"HTTP {e.code} from /accounts (params {sorted(params)}): {e.read()[:200].decode(errors='replace')}") return {} @@ -168,9 +170,12 @@ def cmd_claim() -> None: claim = base64.b64decode(token).decode() if not claim.startswith("https://"): die("Setup Token did not decode to an https URL") - req = urllib.request.Request(claim, method="POST", data=b"", headers={"Content-Length": "0"}) - with urllib.request.urlopen(req, timeout=60) as r: - url = r.read().decode().strip() + req = urllib.request.Request(claim, method="POST", data=b"", headers={"Content-Length": "0", "User-Agent": UA}) + try: + with urllib.request.urlopen(req, timeout=60) as r: + url = r.read().decode().strip() + except urllib.error.HTTPError as e: + die(f"HTTP {e.code} from claim: {e.read()[:200].decode(errors='replace')}") print("\nAccess URL obtained (not printed). A Setup Token can be claimed only once,") print("so save the Access URL to Vaultwarden now; `run` will prompt for it.") if input("Show it once to copy into Vaultwarden? [y/N] ").lower() == "y":