From 2a8fbe1c0665383d8874f599640854b3ec6b841c Mon Sep 17 00:00:00 2001 From: Florian Pigorsch Date: Tue, 9 Apr 2024 20:16:51 +0200 Subject: [PATCH] add timeout when downloading files --- examples/us_capitals.py | 2 +- staticmaps/tile_downloader.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/us_capitals.py b/examples/us_capitals.py index 98c086b..b9a357c 100644 --- a/examples/us_capitals.py +++ b/examples/us_capitals.py @@ -14,7 +14,7 @@ "https://gist.githubusercontent.com/jpriebe/d62a45e29f24e843c974/" "raw/b1d3066d245e742018bce56e41788ac7afa60e29/us_state_capitals.json" ) -response = requests.get(URL) +response = requests.get(URL, timeout=10) for _, data in json.loads(response.text).items(): capital = staticmaps.create_latlng(float(data["lat"]), float(data["long"])) context.add_object(staticmaps.Marker(capital, size=5)) diff --git a/staticmaps/tile_downloader.py b/staticmaps/tile_downloader.py index 353f1ba..51a55d4 100644 --- a/staticmaps/tile_downloader.py +++ b/staticmaps/tile_downloader.py @@ -54,7 +54,7 @@ def get(self, provider: TileProvider, cache_dir: str, zoom: int, x: int, y: int) url = provider.url(zoom, x, y) if url is None: return None - res = requests.get(url, headers={"user-agent": self._user_agent}) + res = requests.get(url, headers={"user-agent": self._user_agent}, timeout=10) if res.status_code == 200: data = res.content else: