Search code examples
pythonattributeerroropenweathermap

PyOWM 'Observation' object has no attribute 'observation'


This code is pulled directly from the PyOWM docs:

from pyowm.owm import OWM
owm = OWM('your-api-key')
mgr = owm.weather_manager()
pressure_dict = mgr.weather_at_place('Berlin,DE').observation.pressure
pressure_dict['press']
pressure_dict['sea_level']

I have an API key that works. The package seems to work when I am calling temperatures from another attribute, but this code results in: AttributeError: 'Observation' object has no attribute 'observation' when run.

Any ideas as to what I am missing?


Solution

  • PyOWM author here - it's a bug in the docs (tracked and will be fixed)

    The example should be:

    from pyowm.owm import OWM
    owm = OWM('your-api-key')
    mgr = owm.weather_manager()
    pressure_dict = mgr.weather_at_place('Berlin,DE').weather.pressure  # 'weather', not 'observation'
    pressure_dict['press']
    pressure_dict['sea_level']
    

    This is because mgr.weather_at_place('Berlin,DE') gives an Observation object which embeds a Weather object instance