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 'weather_at_place'` #313

Closed filiptronicek closed 4 years ago

filiptronicek commented 4 years ago

GitHub actions returned this error code, after hundreds of successful runs. Run python main.py Traceback (most recent call last): File "main.py", line 68, in <module> csvArrIn = getWeatherInfo(city) File "main.py", line 35, in getWeatherInfo obs = owm.weather_at_place(city+',CZ') AttributeError: 'OWM' object has no attribute 'weather_at_place'

geofbaum commented 4 years ago

@filiptronicek

From the short part of code that is visible in the error message it appears that you're missing a step to call 'weather_at_place' as it looks like you're trying to directly call it from owm.

Per the docs and altered to show your code usage the steps to call that attribute require calling weather_manager() before:

owm = OWM('your-api-key')
mgr = owm.weather_manager()
observation = mgr.weather_at_place(city+',CZ')
filiptronicek commented 4 years ago

This is my function from my code:

def getWeatherInfo(city: str):
    owm = OWM(API_key)
    obs = owm.weather_at_place(city+',CZ')
    w = obs.get_weather()
filiptronicek commented 4 years ago

I will try to use the weather_manager, but is this a new feature? It worked yesterday just fine.

geofbaum commented 4 years ago

Yes your code would have worked with the previous release of pyowm. And yes the weather_manager is a new feature in that it is the new way to call this now with the 3.0 Release of pyowm. It was released within the last 24hrs so if you're code in your github actions flow was just referencing the code here, that's now changed. You might want to just take a look at your code if you're referencing pyowm anywhere else in your workflow to make sure there aren't any other changes between the two releases that might cause an error.

Hopefully there's only a line or two to change on your side to get everything working with the new release.

csparpa commented 4 years ago

Hey @filiptronicek as per announcements and relative documentation PyOWM v3 is a major release and as such does not offer retrocompatibility with v2 library interface. yes, hopefully it will only take a few touches to your code to get everything sorted out

csparpa commented 4 years ago

By the way, lesson learned: never have your code depend upon libraries without checking that newer releases don't break it. this is easy done eg. with pip by ensuring that the next major release is never hit

filiptronicek commented 4 years ago

@csparpa thanks for the advice. Makes sense.

filiptronicek commented 4 years ago

@geofbaum is this code correct? Throws an error still

def getWeatherInfo(city: str):
    owm = OWM(API_key)
    mgr = owm.weather_manager()
    obs = mgr.weather_at_place(city+',CZ')
    w = obs.get_weather()
csparpa commented 4 years ago

Nope

replace "get_weather()" with "weather"

Java-style getters have been removed in pyowm v3

Claudio Sparpaglione csparpa@gmail.com http://linkedin.com/in/claudiosparpaglione

On Sun, May 31, 2020, 19:36 Filip Troníček notifications@github.com wrote:

@geofbaum https://github.com/geofbaum is this code correct? Throws an error still

def getWeatherInfo(city: str): owm = OWM(API_key) mgr = owm.weather_manager() obs = mgr.weather_at_place(city+',CZ') w = obs.get_weather()

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/csparpa/pyowm/issues/313#issuecomment-636503052, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABHOXXSDA7IAYA3D4BAOK6LRUKIR5ANCNFSM4NPEQFRQ .

filiptronicek commented 4 years ago

image Doesn't seem that it would work.

csparpa commented 4 years ago

Remove the () as it's a property, not a function

Claudio Sparpaglione csparpa@gmail.com http://linkedin.com/in/claudiosparpaglione

On Sun, May 31, 2020, 20:09 Filip Troníček notifications@github.com wrote:

[image: image] https://user-images.githubusercontent.com/29888641/83359438-8ae7b500-a37a-11ea-9eb1-a05154db99b3.png Doesn't seem that it works.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/csparpa/pyowm/issues/313#issuecomment-636506910, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABHOXXWDTPZV2FNIZDZ6SU3RUKMNBANCNFSM4NPEQFRQ .

filiptronicek commented 4 years ago

Thanks, everything working again!

anebz commented 3 years ago

@csparpa what is the v2 equivalent of weather_manager? I'm trying to deploy a code to Scrapinghub but I have to use an older version of it and when I try to deploy it, I get this error:

AttributeError: 'OWM25' object has no attribute 'weather_manager'`
csparpa commented 3 years ago

Hi,

all weather_manager functions in v2 must be invoked on the OWM object instance directly...

On Thu, Sep 17, 2020, 13:02 Ane notifications@github.com wrote:

@csparpa https://github.com/csparpa what is the v2 equivalent of weather_manager? I'm trying to deploy a code to Scrapinghub https://www.scrapinghub.com/scrapy-cloud/ but I have to use an older version of it and when I try to deploy it, I get this error:

AttributeError: 'OWM25' object has no attribute 'weather_manager'`

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/csparpa/pyowm/issues/313#issuecomment-694158548, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABHOXXTBYJWZLKYXWLJDWLTSGHUEVANCNFSM4NPEQFRQ .

anebz commented 3 years ago

I don't follow, how does it change from the v3 version of my code?

from pyowm import OWM

owm = OWM('my-api')
mgr = owm.weather_manager()
observation = mgr.weather_at_place(...)

Do you mean this?

owm = OWM('my-api')
observation = owm.weather_at_place(...)
csparpa commented 3 years ago

Exactly!

Anyway, you can find the v2 docs here: https://github.com/csparpa/pyowm/blob/2.10-LTS/sphinx/usage-examples-v2/weather-api-usage-examples.md#getting-currently-observed-weather-for-a-specific-location

Hope this helps

dothechuyen commented 3 years ago

image help me, pls!

dothechuyen commented 3 years ago

image

Blackniku commented 2 years ago

@dothechuyen replace "get_weather()" with "weather"