aerodatabox: add browser User-Agent, fixes 403 from Cloudflare/RapidAPI gateway
This commit is contained in:
+9
-1
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user