open-meteo / open-meteo

Free Weather Forecast API for non-commercial use
https://open-meteo.com
GNU Affero General Public License v3.0
2.67k stars 173 forks source link

OpenMeteoRequestsError: {'error': True, 'reason': 'Invalid timezone'} #589

Closed aandrovitsanea closed 10 months ago

aandrovitsanea commented 10 months ago

Triggered by iata = KAO, latitude=65.97 , longitude=29.33

~/weather.py in weather_calls(latitude, longitude, start_date, end_date, commercial) 57 58 ---> 59 responses = openmeteo.weather_api(url, 60 params=params) 61

~/.local/lib/python3.10/site-packages/openmeteo_requests/Client.py in weather_api(self, url, params) 45 def weather_api(self, url: str, params: any) -> list[WeatherApiResponse]: 46 """Get and decode as weather api""" ---> 47 return self._get(WeatherApiResponse, url, params) 48 49 def del(self):

~/.local/lib/python3.10/site-packages/openmeteo_requests/Client.py in _get(self, cls, url, params) 28 if response.status_code in [400, 429]: 29 response_body = response.json() ---> 30 raise OpenMeteoRequestsError(response_body) 31 32 response.raise_for_status()

OpenMeteoRequestsError: {'error': True, 'reason': 'Invalid timezone'}

patrick-zippenfenig commented 10 months ago

Hi, could you post the API URL and Parameter? On first try, the timezone detection for KAO works fine: https://api.open-meteo.com/v1/forecast?latitude=65.97&longitude=29.33&hourly=temperature_2m&timezone=auto

aandrovitsanea commented 10 months ago

url = "https://customer-archive-api.open-meteo.com/v1/archive" params = { "latitude": latitude, "longitude": longitude, "start_date": start_date, "end_date": end_date, "hourly": [ "temperature_2m", "relative_humidity_2m", "precipitation", "rain", "snowfall", "snow_depth", "weather_code", "surface_pressure", "cloud_cover", "cloud_cover_low", "cloud_cover_mid", "cloud_cover_high", "wind_speed_10m", "wind_speed_100m", "wind_direction_10m", "wind_direction_100m", "wind_gusts_10m" ], "timeformat": "unixtime", "timezone": "auto" }

# Add the API key for commercial use
if commercial:
    params["apikey"] = "XXXXXXXXXXXXX"

responses = openmeteo.weather_api(url,
                                  params=params)
patrick-zippenfenig commented 10 months ago

Thanks for the details. I am still having issues to reproduce the issue with the historical archive API. Seems to be working for me: https://archive-api.open-meteo.com/v1/archive?latitude=65.97&longitude=29.33&start_date=2023-12-27&end_date=2024-01-10&hourly=temperature_2m&timezone=auto

Could you post the exact coordinates?

I was also rolling out an API update at 10:00 local time (CET), minutes before you reported the issue. Just maybe it got fixed with this update already.

aandrovitsanea commented 10 months ago

Thanks for the support!

Here is an update:

iata: CUR, lat: 12.2, lon: -68.97

triggered the OpenMeteoRequestsError: {'error': True, 'reason': 'Invalid timezone'}

I just rerun the script by adding if iata != 'CUR': run and it run till the end.

Reminder, error raises only when "timezone": "auto", if ie "timezone": "GMT" then it works.

patrick-zippenfenig commented 10 months ago

Got it! Most likely the polygon for Curacao island was not correctly defined. I implemented a workaround in https://github.com/patrick-zippenfenig/SwiftTimeZoneLookup/commit/9fc508efb2f0bb0d92fb2d4bd49c26260d00e42f

I quickly deployed the fix to the historical archive API. Please feel free to reopen if the issue persists for other locations.

aandrovitsanea commented 10 months ago

Cool! Thanks a lot Patrick for your support and work!

I just got the same error for:

iata latitude longitude
BLA 10.12 -64.70
BON 12.13 -68.28
CCS 10.61 -66.98
EOR 6.73 -61.58
GND 12.05 -61.73
PMV 10.97 -63.83
POS 10.65 -61.52
STD 7.58 -72.07
TAB 11.15 -60.84
VLN 10.15 -68.03

with respective urls:

https://archive-api.open-meteo.com/v1/archive?latitude=7.58&longitude=-72.07&start_date=2023-07-08&end_date=2023-08-08&hourly=temperature_2m&timezone=auto

https://archive-api.open-meteo.com/v1/archive?latitude=11.15&longitude=-60.84&start_date=2023-07-08&end_date=2023-08-08&hourly=temperature_2m&timezone=auto

https://archive-api.open-meteo.com/v1/archive?latitude=10.97&longitude=-63.83&start_date=2023-07-08&end_date=2023-08-08&hourly=temperature_2m&timezone=auto

https://archive-api.open-meteo.com/v1/archive?latitude=10.65&longitude=-61.52&start_date=2023-07-08&end_date=2023-08-08&hourly=temperature_2m&timezone=auto

https://archive-api.open-meteo.com/v1/archive?latitude=12.05&longitude=-61.73&start_date=2023-07-08&end_date=2023-08-08&hourly=temperature_2m&timezone=auto

https://archive-api.open-meteo.com/v1/archive?latitude=10.15&longitude=-68.03&start_date=2023-07-08&end_date=2023-08-08&hourly=temperature_2m&timezone=auto

https://archive-api.open-meteo.com/v1/archive?latitude=6.73&longitude=-61.5&start_date=2023-07-08&end_date=2023-08-08&hourly=temperature_2m&timezone=auto

https://archive-api.open-meteo.com/v1/archive?latitude=12.13&longitude=-68.28&start_date=2023-07-08&end_date=2023-08-08&hourly=temperature_2m&timezone=auto

https://archive-api.open-meteo.com/v1/archive?latitude=10.61&longitude=-66.98&start_date=2023-07-08&end_date=2023-08-08&hourly=temperature_2m&timezone=auto

https://archive-api.open-meteo.com/v1/archive?latitude=10.12&longitude=-64.7&start_date=2023-07-08&end_date=2023-08-08&hourly=temperature_2m&timezone=auto