Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The API worhs for weather_at_place() but not for forecast_at_place() #316

Closed
EightFawn opened this issue Jun 4, 2020 · 21 comments
Closed
Milestone

Comments

@EightFawn
Copy link

The API works with:

owm = pyowm.OWM(owm_token)
mgr = owm.weather_manager()
obs = mgr.weather_at_place('Roma')

But if I use:

daily_forecast = mgr.forecast_at_place('Roma', 'daily').forecast

It give me this error:

raise exceptions.UnauthorizedError('Invalid API Key provided')
pyowm.commons.exceptions.UnauthorizedError: Invalid API Key provided

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.

@csparpa
Copy link
Owner

csparpa commented Jun 7, 2020

@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!

@Karan-Ghatt
Copy link

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!

@csparpa
Copy link
Owner

csparpa commented Jun 8, 2020

Could you pls paste here the output of a print of your OWM object instance?
That is to say:

print(owm)

thanks

@EightFawn
Copy link
Author

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)>

@csparpa
Copy link
Owner

csparpa commented Jun 8, 2020

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?

@EightFawn
Copy link
Author

I create a new API key but I have to wait that openweathermap verify the key

@EightFawn
Copy link
Author

It gives the same error...

@EightFawn
Copy link
Author

I tried to remove the part of the weather and leave only forecast but it still not working

@csparpa
Copy link
Owner

csparpa commented Jun 9, 2020

@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

@EightFawn
Copy link
Author

Ok I try thanks

@EightFawn
Copy link
Author

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

@EightFawn
Copy link
Author

I have to open another issue for this?

@csparpa
Copy link
Owner

csparpa commented Jun 13, 2020

No, I'll check this out
thanks

@geofbaum
Copy link

@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.

@EightFawn
Copy link
Author

Yes, now it works, thanks

@csparpa
Copy link
Owner

csparpa commented Jun 13, 2020

Ok, I'll patch the docs then

@csparpa csparpa closed this as completed Jun 18, 2020
@csparpa csparpa added this to the 3.1 milestone Jun 25, 2020
@raghuvarranvh
Copy link

@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

@Polly333
Copy link

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?

@csparpa
Copy link
Owner

csparpa commented Jul 10, 2021

@Polly333 yep

@ividal
Copy link

ividal commented Jan 27, 2022

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).

@csparpa
Copy link
Owner

csparpa commented Jan 27, 2022

@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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants