Answer the question
In order to leave comments, you need to log in
Why doesn't my Telegram weather bot work in python?
I recently started learning Python, made a telegram bot on it using a video lesson, also found a question on the same bot on this site (Toaster) and copied it a bit. I received my weather and bot tokens, entered (where ***), but when I start it on the PC, a lot of incomprehensible errors come out, please help me figure out what's wrong, maybe there are spelling errors? And also tell us how and where it is better to run this bot so that it works without a PC turned on, thanks in advance, I'm waiting for answers ...
Here is the code itself:
import pyowm
import telebot
owm = pyowm.OWM('***', language='ru')
bot = telebot.TeleBot('***')
@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 pyowm.exceptions.api_response_error.NotFoundError:
bot.send_message(message.chat.id, 'Город не найден!')
bot.polling(none_stop=True)
Answer the question
In order to leave comments, you need to log in
The question is closed, I found a solution, everything was correct in the code, it was only necessary to install a VPN) ;)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question