I'm testing code to use on a bot, I've created an account on OpenWeatherMap and got an API Key
It is my understanding that a Free account on OWM lets get the daily forecast
from pyowm import OWM
from pyowm.utils import config
from pyowm.utils import timestamps
owm = OWM('c548bc34f606696689b7c67ce8cbdbc7')
mgr = owm.weather_manager()
observation = mgr.weather_at_place('Leiria, PT')
w = observation.weather
print(w.detailed_status)
print(w.wind())
print(w.humidity)
print(w.temperature('celsius'))
print(w.rain)
print(w.heat_index)
print(w.clouds)
forecast = mgr.forecast_at_place('Leiria, PT', 'daily')
answer = forecast.will_be_clear_at(timestamps.tomorrow())
print(answer)
clear sky
{'speed': 4.12, 'deg': 80}
43
{'temp': 22.77, 'temp_max': 23.33, 'temp_min': 22.0, 'feels_like': 19.81, 'temp_kf': None}
{}
None
0
This was expected, I got the values for the place I wrote for that time but for the part where I call for forecast_at_place()
I got this
Traceback (most recent call last):
File "c:\Users\AndreClerigo\Desktop\Git\weather_twitterbot\tempCodeRunnerFile.py", line 19, in <module>
forecast = mgr.forecast_at_place('Leiria, PT', 'daily')
File "C:\Users\AndreClerigo\AppData\Local\Programs\Python\Python39\lib\site-packages\pyowm\weatherapi25\weather_manager.py", line 291, in forecast_at_place
_, json_data = self.http_client.get_json(uri, params=params)
File "C:\Users\AndreClerigo\AppData\Local\Programs\Python\Python39\lib\site-packages\pyowm\commons\http_client.py", line 140, in get_json
HttpClient.check_status_code(resp.status_code, resp.text)
File "C:\Users\AndreClerigo\AppData\Local\Programs\Python\Python39\lib\site-packages\pyowm\commons\http_client.py", line 283, in check_status_code
raise exceptions.UnauthorizedError('Invalid API Key provided')
pyowm.commons.exceptions.UnauthorizedError: Invalid API Key provided
Does anyone know what the issue is?
This is an image from the website, but it seeems that daily forecast isn't working
Note: I've already created and tested new keys but this error keeps happening
The forecast_at_place() only works for old API Keys(or legacy keys) and doesn't work for newer keys as per my knowledge, its not the method issues its just that the newer version of API doesn't seems to work or support.
Please refer this: https://pyowm.readthedocs.io/en/latest/v3/code-recipes.html#onecall.
You can use locations_for() method.
So you should be able to retrieve both observed and daily forecasted data using the OneCall methods.