Answer the question
In order to leave comments, you need to log in
Telegram bot on TelegramBotApi. How to solve this error?
Good afternoon. I wrote a bot in Python for Telegram and ran into this error:
raise api_response_error.NotFoundError('Unable to find the resource')
pyowm.exceptions.api_response_error.NotFoundError: The searched item was not found.
Reason: Unable to find the resource.
...
elif message.text == " Температура":
bot.send_message(message.chat.id, "Введите город: ")
def weather():
owm = pyowm.OWM('...')
city = message.text
observation = owm.weather_at_place( city )
w = observation.get_weather()
weather()
bot.send_message(message.chat.id, f"Температура в {city} сейчас: {temperature}")
...
Answer the question
In order to leave comments, you need to log in
Your piece of code is not very informative.
After the line 'city = message.text' add 'print(city)' and see the output in the console.
Here is the simplest code, check with yours:
import telebot
import pyowm
owm = pyowm.OWM('')
bot = telebot.TeleBot('')
def getWeather(city):
observation = owm.weather_at_place(city)
w = observation.get_weather()
temp = w.get_temperature('celsius')["temp"]
return temp
@bot.message_handler(content_types=['text'])
def repeat_all_message(message):
try:
temp = getWeather(message.text)
bot.send_message(message.chat.id,f'Температура в {message.text} - {temp}')
except pyowm.exceptions.api_response_error.NotFoundError:
bot.send_message(message.chat.id,'Ошибка! Город не найден!')
if __name__ == '__main__':
bot.polling(none_stop=True)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question