Answer the question
In order to leave comments, you need to log in
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
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']
Try replacing "w = observation.get_weather()" with "w = observation.weather".
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question