aerodatabox: add browser User-Agent, fixes 403 from Cloudflare/RapidAPI gateway

This commit is contained in:
2026-09-15 22:22:33 +10:00
parent d524e6d343
commit 5d2a7cde77
3 changed files with 60 additions and 2 deletions
+9 -1
View File
@@ -100,8 +100,16 @@ def lookup_gate_times(flight_number: str, flight_date: date) -> dict | None:
f"{BASE_URL}/flights/number/{cleaned}/{flight_date.isoformat()}"
"?dateLocalRole=Both&withAircraftImage=false&withLocation=false"
)
# A default urllib request (no User-Agent) gets HTTP 403 from AeroDataBox's
# Cloudflare-fronted gateway even with a perfectly valid, subscribed key -
# confirmed live, side by side, same key/URL: bare urllib -> 403, same
# request + this UA -> 200 with real data. See config.BROWSER_USER_AGENT.
req = urllib.request.Request(
url, headers={"x-rapidapi-key": config.AERODATABOX_API_KEY}
url,
headers={
"x-rapidapi-key": config.AERODATABOX_API_KEY,
"User-Agent": config.BROWSER_USER_AGENT,
},
)
try:
with urllib.request.urlopen(req, timeout=20) as resp: