Skip to content

Commit

Permalink
Add custom useragent
Browse files Browse the repository at this point in the history
tiles.openstreetmap.org was blocking the default Python
user agent
  • Loading branch information
Cj-Malone committed Jun 1, 2022
1 parent 5a1bc60 commit 2890548
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion tiles_to_tiff/tiles_to_tiff.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,16 @@ def fetch_tile(x, y, z, tile_source):
return url.replace("file:///", "")

path = f'{temp_dir}/{x}_{y}_{z}.png'
urllib.request.urlretrieve(url, path)
req = urllib.request.Request(
url,
data=None,
headers={
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) tiles-to-tiff/1.0 (+https://github.com/jimutt/tiles-to-tiff)'
}
)
g = urllib.request.urlopen(req)
with open(path, 'b+w') as f:
f.write(g.read())
return path


Expand Down

0 comments on commit 2890548

Please sign in to comment.