fix(pi): set a User-Agent on the APK updater so Cloudflare doesn't 403 it

This commit is contained in:
Mathieu Moran
2026-08-15 21:02:54 -04:00
parent 23c044b5e0
commit a050f3577a
+7 -2
View File
@@ -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") 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") 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): def sha256_file(path):
h = hashlib.sha256() h = hashlib.sha256()
@@ -30,7 +33,8 @@ def sha256_file(path):
def fetch_json(url, timeout=20): 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) return json.load(r)
@@ -63,7 +67,8 @@ def main():
os.makedirs(APP_DIR, exist_ok=True) os.makedirs(APP_DIR, exist_ok=True)
tmp = APK_PATH + ".part" tmp = APK_PATH + ".part"
try: 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: while True:
chunk = r.read(1024 * 1024) chunk = r.read(1024 * 1024)
if not chunk: if not chunk: