Skip to content

Commit c1b76e0

Browse files
committed
autotest: fix error when downloading projjson.schema.json
1 parent ed8bd4e commit c1b76e0

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

autotest/pymod/gdaltest.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1896,7 +1896,9 @@ def gdalurlopen(url, timeout=10):
18961896
import http.client
18971897

18981898
try:
1899-
handle = urllib.request.urlopen(url)
1899+
handle = urllib.request.urlopen(
1900+
urllib.request.Request(url, headers={"User-Agent": "GDAL"})
1901+
)
19001902
socket.setdefaulttimeout(old_timeout)
19011903
return handle
19021904
except urllib.error.HTTPError as e:

swig/python/gdal-utils/osgeo_utils/samples/validate_geoparquet.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,13 @@ def versiontuple(v):
9999
def retrieve_remote_file(uri: str):
100100
if not uri.startswith("http://") and not uri.startswith("https://"):
101101
raise Exception(f"Cannot retrieve {uri}")
102-
import urllib
102+
import urllib.request
103103

104104
global map_remote_resources
105105
if uri not in map_remote_resources:
106-
response = urllib.request.urlopen(uri).read()
106+
response = urllib.request.urlopen(
107+
urllib.request.Request(uri, headers={"User-Agent": "GDAL"})
108+
).read()
107109
map_remote_resources[uri] = response
108110
else:
109111
response = map_remote_resources[uri]
@@ -171,10 +173,14 @@ def _check(self):
171173
schema_url = f"https://github.com/opengeospatial/geoparquet/releases/download/v{version}/schema.json"
172174

173175
if schema_url not in geoparquet_schemas:
174-
import urllib
176+
import urllib.request
175177

176178
try:
177-
response = urllib.request.urlopen(schema_url).read()
179+
response = urllib.request.urlopen(
180+
urllib.request.Request(
181+
schema_url, headers={"User-Agent": "GDAL"}
182+
)
183+
).read()
178184
except Exception as e:
179185
return self._error(
180186
f"Cannot download GeoParquet JSON schema from {schema_url}. Exception = {repr(e)}"

0 commit comments

Comments
 (0)