From 5da755a49622d7d31e86cdf8324efca6c4e9dde3 Mon Sep 17 00:00:00 2001 From: Vincent Bernat Date: Wed, 15 Dec 2021 21:19:53 +0100 Subject: [PATCH] polybar-weather: add a timeout to requests --- bin/polybar-weather | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bin/polybar-weather b/bin/polybar-weather index 7ce4c66..ad220e7 100755 --- a/bin/polybar-weather +++ b/bin/polybar-weather @@ -20,6 +20,7 @@ def get_location(): r = requests.get( "https://www.maxmind.com/geoip/v2.1/city/me", headers={"referer": "https://www.maxmind.com/en/locate-my-ip-address"}, + timeout=10, ) r.raise_for_status() data = r.json() @@ -45,6 +46,7 @@ def get_weather(apikey, latitude, longitude): "units": "metric", "exclude": "minutely,hourly", }, + timeout=10, ) r.raise_for_status() data = r.json() @@ -145,7 +147,7 @@ if __name__ == "__main__": try: location, city = get_location() break - except requests.exceptions.ConnectionError: + except (requests.exceptions.ConnectionError, requests.exceptions.Timeout): # Wait to be online logger.info("not online, waiting") update_status("", options.output)