D
D
dmbgdnwtch2021-06-12 16:03:14
Python
dmbgdnwtch, 2021-06-12 16:03:14

The program gives an error "NoneType' object has no attribute 'get_weather'", how to fix the code?

I marked the wrong line
import sys, pyowm
from PySide2 import QtCore, QtGui, QtWidgets
from des import Ui_Dialog

app = QtWidgets.QApplication(sys.argv)

Dialog = QtWidgets.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog. show()

def get_weather_city():
owm = pyowm.OWM( '1b28fe5b2738c9d7561379ff8172e4f9' )
city = ui.lineEdit.text()
observation = owm.weather_at_place(city)
w = observation.get_weather() #error here
temperature = w.get_temperature ('celsius')['temp']
ui.label.setText(f'Temperature: {temperature}')

ui.pushButton.clicked.connect(get_weather_city)

sys.exit(app.exec_())

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
o5a, 2021-06-14
@dmbgdnwtch

It's some old syntax. Now it's done like this:

owm = pyowm.OWM('КЛЮЧ')
mgr = owm.weather_manager()
observation = mgr.weather_at_place(city)
w = observation.weather
temperature = w.temperature('celsius')['temp']

M
MDan_Twenty_One, 2021-06-12
@MDan_Twenty_One

Try replacing "w = observation.get_weather()" with "w = observation.weather".

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question