S
S
Sergey Kaplukh2020-12-02 11:34:51
Python
Sergey Kaplukh, 2020-12-02 11:34:51

Telegram weather bot error "City not found"?

import pyowm
import telebot

owm = pyowm.OWM(xxxxxxxxxxxxxxxxx, {'language': 'ru'})
bot = telebot.TeleBot('xxxxxxxxxxxxxxxxxxxxxx')


@bot.message_handler(content_types=['text'])
def send_echo(message):
    try:
        observation = owm.weather_at_place(message.text)
        w = observation.get_weather()
        temp = w.get_temperature('celsius')['temp']

        answer = f"В городе {message.text} сейчас {w.get_detailed_status()} \n"
        answer += f"Приблизительная температура {round(temp)} градусов\n\n"

        if temp < 0:
            answer += 'Сейчас температура ниже нуля, одевайся теплее!'
        elif temp < 20:
            answer += 'Сейчас прохладно, стоит потеплей одеться!'
        else:
            answer += 'Сейчас достаточно тепло, можно одеться легко!'

        bot.send_message(message.chat.id, answer)
    except:
        bot.send_message(message.chat.id,'Ошибка! Город не найден.')
bot.polling( none_stop = True)
input()


The problem is that when writing the city, the inscription "Error! The city was not found."
I rewrote the code, it did not work, maybe someone knows what the error is ??

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
o5a, 2020-12-02
@o5a

In new versions of the owm library, you need to use manager to work, and request data through it

owm = pyowm.OWM(OWM_KEY, {'language': 'ru'})
mgr = owm.weather_manager()
observation = mgr.weather_at_place(location)

H
HemulGM, 2020-12-02
@HemulGM

There is such word "debugging". Do you know?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question