From a050f3577af0af00085a8e1e294a7c0cf2dcda6e Mon Sep 17 00:00:00 2001 From: Mathieu Moran Date: Sat, 15 Aug 2026 21:02:54 -0400 Subject: [PATCH] fix(pi): set a User-Agent on the APK updater so Cloudflare doesn't 403 it --- deploy/yaris_app_updater.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/deploy/yaris_app_updater.py b/deploy/yaris_app_updater.py index 3866f78..6db4302 100644 --- a/deploy/yaris_app_updater.py +++ b/deploy/yaris_app_updater.py @@ -20,6 +20,9 @@ SERVER_URL = os.environ.get("YARIS_SERVER_URL", "https://yaris.ceaf.dev").rstrip APP_DIR = os.environ.get("YARIS_APP_DIR", "/home/yaris/app/yaris-obd/static/app") APK_PATH = os.path.join(APP_DIR, "yaris-obd.apk") +# Cloudflare blocks the default Python-urllib UA with 403 — identify ourselves. +_HEADERS = {"User-Agent": "yaris-obd-updater/1.0"} + def sha256_file(path): h = hashlib.sha256() @@ -30,7 +33,8 @@ def sha256_file(path): def fetch_json(url, timeout=20): - with urllib.request.urlopen(url, timeout=timeout) as r: + req = urllib.request.Request(url, headers=_HEADERS) + with urllib.request.urlopen(req, timeout=timeout) as r: return json.load(r) @@ -63,7 +67,8 @@ def main(): os.makedirs(APP_DIR, exist_ok=True) tmp = APK_PATH + ".part" try: - with urllib.request.urlopen(f"{SERVER_URL}/app/yaris-obd.apk", timeout=600) as r, open(tmp, "wb") as f: + req = urllib.request.Request(f"{SERVER_URL}/app/yaris-obd.apk", headers=_HEADERS) + with urllib.request.urlopen(req, timeout=600) as r, open(tmp, "wb") as f: while True: chunk = r.read(1024 * 1024) if not chunk: