From 349926d421b04a25c80e233e8a8033d3f35d919b Mon Sep 17 00:00:00 2001 From: zyphlar Date: Tue, 21 Apr 2026 22:31:31 -0700 Subject: [PATCH] Fix 406 error from Overpass API by setting Accept: */* header --- download-overpass.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/download-overpass.py b/download-overpass.py index 11d65aa..fd5e219 100644 --- a/download-overpass.py +++ b/download-overpass.py @@ -86,11 +86,16 @@ def query_overpass(query): """Send query to Overpass API and return JSON response, with retries.""" url = "https://overpass-api.de/api/interpreter" data = urllib.parse.urlencode({"data": query}).encode("utf-8") + req = urllib.request.Request( + url, + data=data, + headers={"Accept": "*/*", "User-Agent": "TheVillagesImport/1.0"}, + ) max_attempts = 3 for attempt in range(1, max_attempts + 1): try: - with urllib.request.urlopen(url, data=data, timeout=300) as response: + with urllib.request.urlopen(req, timeout=300) as response: return json.loads(response.read().decode("utf-8")) except urllib.error.HTTPError as e: try: