question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:21 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
Polly333commented, Jul 10, 2021
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?

1reaction
csparpacommented, 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 😒

Luckily, you’ll hopefylly be able to retrieve both observed and daily forecasted data using the OneCall methods

Read more comments on GitHub >

github_iconTop Results From Across the Web

PyOWM - Weather API not working as expected - Stack Overflow
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...
Read more >
How to Use an API: Just the Basics 2022 | TechnologyAdvice
Ever wonder what an API is or how to use one? APIs allow one program to request data from another. Learn more about...
Read more >
What Is an API? How APIs Work (for Non-Developers) - Auth0
An API is an intermediary piece of code that allows pieces of software to communicate with each other. APIs can speed the development...
Read more >
How do APIs work? An in-depth guide - Tray.io
API stands for “application programming interface.” An API is essentially a set of rules that dictate how two machines talk to each other....
Read more >
Introduction to web APIs - Learn web development | MDN
At this point, you should have a good idea of what APIs are, how they work, and what you can do with them...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found