@Ramario0021
Начальный программист)

Почему вылазит ошибка: AttributeError: 'Observation' object has no attribute 'get_weather' когда я нажимаю на кнопку «Найти»?

Вот полная ошибка из cmd:
D:\Programm weather>python main.py
Traceback (most recent call last):
File "C:\Users\Admin\AppData\Local\Programs\Python\Python39\lib\site-packages\eel\__init__.py", line 281, in _process_message
return_val = _exposed_functions[message['name']](*message['args'])
File "D:\Programm weather\main.py", line 9, in get_weather
observation = weather = observation.get_weather()
AttributeError: 'Observation' object has no attribute 'get_weather'

Вот код пайтон:
import eel 
import pyowm
# api key
owm = pyowm.OWM ( '80e8e723ef945c291f4661f5898f93e0')
@eel.expose
def get_weather(place):
    #owm
    observation = owm.weather_manager().weather_at_place(place)
    observation = weather = observation.get_weather()
    #temp
    Temp = weather.get_temperature('celsius')['temp']
    #status
    Status = weather.get_detailed_status()
    return "В городе "+place+'температура '+str(Temp) + Status

#eel
eel.init("D:\Programm weather\web")
eel.start("main.html", size=(500 , 500))


Вот код HTML и Js:
<!DOCTYPE html>
<html lang="ru">
<head>
    <meta charset="UTF-8">
    <title>Weather</title>
    <script src="eel.js"></script>
    <link rel="icon" type="image/png" href="favicon.png">
    <link rel="stylesheet" href="main.css">
    <link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.css">
    <link rel="icon" type ="image/png" href="weather-icon.png">
</head>
<body>
<div>
    <h2>find weather</h2>
</div>
<div class="form">
    <form>
        <input id='location' class="enter" type="text" placeholder="Введите название города" value="Нью-Йорк, США">
    </form>
</div>
<div>
    <button id='show'>Найти</button>
</div>
<div id="info"></div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script type="text/javascript">
    async function display_weather(){
        let place = document.getElementById('location').value;
        
        let res = await eel.get_weather(place)();
        document.getElementById('info').innerHTML = res;
        }
        jQuery('#show').on('click',function(){
            //
            display_weather();
        });
    </script>
</body>
</html>


Вот код CSS:
* {
    font-family: "Roboto", sans-serif;
    box-sizing: border-box;
    font-weight: 300;
}

body {
    background: #8A2387;
    background: -webkit-linear-gradient(left, #F27121, #E94057, #8A2387);
    background: -o-linear-gradient(left, #F27121, #E94057, #8A2387);
    background: linear-gradient(to right, #F27121, #E94057, #8A2387);

    color: white;
    padding: 50px;
}

#location {
    display: block;
    border: none;
    background: rgba(255, 255, 255, .5);
    border-radius: 10px;
    padding: 20px;
    color: white;
    outline: none;
    width: 100%;
    font-size: 30px;
}

#location:placeholder {
    color: rgba(255, 255, 255, .5);
}

#show {
    display: block;
    border: none;
    margin-top: 15px;
    
    background: -webkit-linear-gradient(left, #667db6, #0082c8, #0082c8, #667db6);
    background: -o-linear-gradient(left, #667db6, #0082c8, #0082c8, #667db6);
    background: linear-gradient(to right, #667db6, #0082c8, #0082c8, #667db6);
    
    border-radius: 10px;
    padding: 20px;
    color: white;
    outline: none;
    width: 100%;
    font-size: 20px;
    text-transform: uppercase;
    font-weight: bold;
    cursor: pointer;
}

#show:hover {
    opacity: .9;
}
  • Вопрос задан
  • 785 просмотров
Решения вопроса 1
@Wispik
потому что нет такого метода get_weather(), есть weather
# вот это
observation = weather = observation.get_weather()
# замени на это
weather = observation.weather
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы