From 7a01f5830c8ae263a8884e4fde84cc8c100b053f Mon Sep 17 00:00:00 2001 From: Markus Heiser Date: Wed, 2 Sep 2026 13:40:53 +0200 Subject: [PATCH] [fix] hardening engine: ddg weather - get GEO location from response (#6623) The previous implementation ran into an error if the search term contained words other than just the location (ValueError was raised). To test engine use search terms like: !ddw weather berlin germany Signed-off-by: Markus Heiser --- searx/engines/duckduckgo_weather.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/searx/engines/duckduckgo_weather.py b/searx/engines/duckduckgo_weather.py index 070d09d85..d7762c7aa 100644 --- a/searx/engines/duckduckgo_weather.py +++ b/searx/engines/duckduckgo_weather.py @@ -109,7 +109,19 @@ def response(resp: SXNG_Response): json_data = loads(resp.text[resp.text.find('\n') + 1 : resp.text.rfind('\n') - 2]) - geoloc = weather.GeoLocation.by_query(resp.search_params["query"]) + location = json_data.get("location") + if not location: + return res + + metadata = json_data.get("weatherAlerts", {}).get("metadata", {}) + geoloc = weather.GeoLocation( + name=location, + latitude=metadata.get("latitude"), + longitude=metadata.get("longitude"), + elevation=0, + country_code=metadata.get("language").split("-")[-1], + timezone=json_data.get("location"), + ) weather_answer = EngineResults.types.WeatherAnswer( current=_weather_data(geoloc, json_data["currentWeather"]),