Closed EightFawn closed 4 years ago
@EightFawn still not working?
I've tried your exact code and it works on my side - I have a free API key Might have been a temporary flicker of the OWM API
Please let me know!
Hi, I seem to be facing a similar issues, I'm trying to run the following code:
from pyowm import OWM
owm = OWM('key')
mgr = owm.weather_manager()
observation = mgr.weather_at_place('London,GB')
w = observation.weather
print(w)
I keep hitting the same error:
raise exceptions.UnauthorizedError('Invalid API Key provided')
pyowm.commons.exceptions.UnauthorizedError: Invalid API Key provided
I am using a valid key, so I'm not too sure whats going on. Any insight would be great!
Could you pls paste here the output of a print of your OWM
object instance?
That is to say:
print(owm)
thanks
It gives me the same error, the output of the print of owm is:
<pyowm.owm.OWM - API key=************************b81f5079, subscription type=free, PyOWM version=(3, 0, 0)>
IoI looks like there is no reason why it shouldn't work!
Short of ideas.. Have you tried creating a new free API key and use that one instead?
I create a new API key but I have to wait that openweathermap verify the key
It gives the same error...
I tried to remove the part of the weather and leave only forecast but it still not working
@EightFawn I've tested your exact code again on my side and it works like a charm
Now, I think here the issue is not with PyOWM but with the API key itself In your very first code snippet you said that querying for observed weather worked but querying for daily forecasted weather didn't: both queries were working fine on my side.
So here my conjecture is: as my free API key was issued years ago and it seems that it calls OWM API endpoints that are now unaccessible to newer API keys.
I've checked out on the OWM API website: it seems that as of today, only calls to the "OneCall" endpoint are enabled for free API key - this might explain why calls work on my side (because I have a kind of "legacy" API key) and don't work on yours.
This behaviour was completely unexpeted to me :-S
Luckily, you'll hopefylly be able to retrieve both observed and daily forecasted data using the OneCall methods
Ok I try thanks
It gives me an error when I try to find the geographic coordinates by the name, I used the same instructions of the wiki , the error is:
city = list_of_locations[0][0]
TypeError: 'Location' object is not subscriptable
I have to open another issue for this?
No, I'll check this out thanks
@EightFawn try the following to see if you get valid lat and lon values.
city = list_of_locations[0]
print(city.lat, city.lon)
@csparpa It appears that the example in the docs has an extra [0]:
from pyowm.owm import OWM
owm = OWM('your-api-key')
reg = owm.city_id_registry()
list_of_locations = reg.locations_for('moscow', country='RU')
moscow = list_of_locations[0][0]
lat = moscow.lat # 55.75222
lon = moscow.lon # 37.615555
As in moscow = list_of_locations[0][0] should be moscow = list_of_locations[0]. Either that or the code is returning something that isn't expected from the Locations class.
Yes, now it works, thanks
Ok, I'll patch the docs then
@EightFawn I've tested your exact code again on my side and it works like a charm
Now, I think here the issue is not with PyOWM but with the API key itself In your very first code snippet you said that querying for observed weather worked but querying for daily forecasted weather didn't: both queries were working fine on my side.
So here my conjecture is: as my free API key was issued years ago and it seems that it calls OWM API endpoints that are now unaccessible to newer API keys.
I've checked out on the OWM API website: it seems that as of today, only calls to the "OneCall" endpoint are enabled for free API key - this might explain why calls work on my side (because I have a kind of "legacy" API key) and don't work on yours.
This behaviour was completely unexpeted to me :-S
Luckily, you'll hopefylly be able to retrieve both observed and daily forecasted data using the OneCall methods
Works like a charm.. Was stumped for a while. thanks
reg = owm.city_id_registry()
list_of_locations = reg.locations_for('Mumbai', country='IN')
Mumbai = list_of_locations[0]
lat = Mumbai.lat
lon = Mumbai.lon
one_call = mgr.one_call(lat, lon)
One_call = one_call.forecast_daily[0].temperature('celsius')
print(One_call)
Does it return temperature for the next day?
@Polly333 yep
If you need to access forecaster's will_have_storm()
, will_have_hurricane()
, etc., which one_call doesn't give access to (as far as I could find) but don't care about the frequency, "3h" instead of "daily" does the trick.
Weirdly enough, this won't work even with a new API key:
forecast = mgr.forecast_at_place('Roma', 'daily').forecast # Invalid API key
but this does work:
forecast = mgr.forecast_at_place('Roma', '3h').forecast
Not sure if this is a problem in pyowm or on the openweathermaps side, but this workaround helped me (pyowm==3.2.0).
@ividal opening up a new issue to investigate what you report
It looks like the old API endpoints started to behave differently (with 3h
) than how they did at the times (with daily
)
Thanks for sharing this!
The API works with:
But if I use:
daily_forecast = mgr.forecast_at_place('Roma', 'daily').forecast
It give me this error:
With only the weather_at_place() code it works but if I add at the same program the forecast_at_place() it gives me this error.