csparpa / pyowm

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

AttributeError: "OWM" object has no attribute #315

Closed LkiZt closed 4 years ago

LkiZt commented 4 years ago

Start code in cmd and always have an AttributeError: "OWM" object has no attribute pip install pyown was successful Code: import pyowm

owm = pyowm.OWM("My API")

place = input(" ")

observation = owm.weather_at_place(place) w = observation.weather print(w)

image

csparpa commented 4 years ago

Hi @LkiZt this happens because now PyOWM is at version 3 and your code thinks it is version 2.x PyOWM 3 is a major release - therefore breaking compatibility with v2 client programs

The patch is easy: instead of

import pyowm

owm = pyowm.OWM("My API")

place = input(" ")

observation = owm.weather_at_place(place)
w = observation.weather
print(w)

just:

import pyowm

owm = pyowm.OWM("My API")

place = input(" ")

mgr = owm.weather_manager()                 # <<<<<
observation = mgr.weather_at_place(place)   # <<<<<

w = observation.weather
print(w)

Let me know if this works for you

LkiZt commented 4 years ago

Hi @csparpa that works. Thank you