fix: get_temp KeyError

This commit is contained in:
Florian Bezannier
2024-02-26 13:10:40 +01:00
committed by Florian BEZANNIER
parent 6f81149f45
commit 9a93f735fc
+3 -3
View File
@@ -17,13 +17,13 @@ def get_temp(latitude: str, longitude: str, api_key: str) -> float:
"units": "metric"},
timeout=TIMEOUT_IN_S)
weather_res_json = weather_rep.json()
temp = weather_res_json.get("current", weather_res_json["main"])["temp"]
temp = weather_res_json.get("current", weather_res_json.get("main"))["temp"]
logger.debug("Temperature :%fc", temp)
return temp
except ConnectionError:
logger.error("Can't connect to openweathermap :", exc_info=True)
except KeyError:
logger.error("Unable to get temperature from openweathermap :", exc_info=True)
except (KeyError, TypeError):
logger.exception("Unable to get temperature from openweathermap :")
return None