csparpa / pyowm

A Python wrapper around the OpenWeatherMap web API
https://pyowm.readthedocs.io
MIT License
789 stars 171 forks source link

Air Pollution Manager #362

Closed RnDCore closed 3 years ago

RnDCore commented 3 years ago

Hello, whenever I call any of the air quality indexes, I get an exception. Python 3.9

e.g. Code: openWMap=pyowm.OWM(APIKEY) mgrAir = openWMap.airpollution_manager()

I get an error when the next line is run

coIndex_1 = mgrAir.coindex_around_coords(51.507351, -0.127758) # London, GB coordinates

Console Output Traceback (most recent call last): File "weatherForecast.py", line 49, in coIndex_1 = mgrAir.coindex_around_coords(51.507351, -0.127758) File "weatherForecast\venv\lib\site-packages\pyowm\airpollutionapi30\airpollution_manager.py", line 68, in coindex_around_coords json_data = self.ap_client.get_coi(params) File "weatherForecast\venv\lib\site-packages\pyowm\airpollutionapi30\airpollution_client.py", line 65, in getcoi , json_data = self._client.get_json(uri) File "weatherForecast\venv\lib\site-packages\pyowm\commons\http_client.py", line 143, in get_json HttpClient.check_status_code(resp.status_code, resp.text) File "weatherForecast\venv\lib\site-packages\pyowm\commons\http_client.py", line 288, in check_status_code raise exceptions.NotFoundError('Unable to find the resource') pyowm.commons.exceptions.NotFoundError: Unable to find the resource

Process finished with exit code 1


Is this a bug? Thank you.

csparpa commented 3 years ago

@RnDCore unfortunately this is not a bug: it's the OWM API that is not able to find any air pollution around the specified coordinates

The only way to get air pollution data from the OWM API is by passing lat/lon coordinates (and this is exactly what PyOWM does) but it looks like for the provided coordinates there is no measurement available

And this is ... weird because the coords are for London city (Trafalgar Square to be precise!) I've tried to send over less decimals for lat/lon, move the sampling point over to different neighborhood in London but no success

You might want to open up a ticket to the OWM service to investigate why they don't have any air pollution data over London

RnDCore commented 3 years ago

Thanks for looking into this. The thing is, if you use the web api, you get the information with no problem, try this: http://api.openweathermap.org/data/2.5/air_pollution?lat=51.507351&lon=-0.127758&appid=yourAPI_Key So, the OWM service seems to be working well. I do get the data by parsing the JSON response but that defies the purpose of using the pyowm library. I haven't managed to get any data using the pyowm library although I tried many different lat/lon coordinates. Something is off... Thanks again!

csparpa commented 3 years ago

@RnDCore actually I owe you apologies - I've investigated this issue better (sorry about the delay I've been super-busy recently) and it looks like PyOWM is calling the old AirPollution API endpoint - which is currently offline

I'm working to introduce support for the calling the new endpoint, which will allow to also download more air quality data than before (eg. Air Quality index, PMX, etc.)

Stay tuned..

csparpa commented 3 years ago

Quick update on this: the fix is on the develop branch (commit 1e3ba96a6cd241e852fce84f29ed451772b9a029) - I've introduced a new object type to handle air quality data.

Will also develop methods to get forecasts and history for it

csparpa commented 3 years ago

Fixed with https://github.com/csparpa/pyowm/commit/52f283e9fb31d3cca3e3604ea9ff1ce0f6508b7e