Условие которое вызывает функцию
Используется библиотека telebot и requests
elif message.text == 'Погода':
markup = types.ReplyKeyboardMarkup(resize_keyboard = True)
back = types.KeyboardButton('Назад')
markup.add(back)
bot.send_message(message.chat.id, 'Введите ваш город')
bot.register_next_step_handler(message, open_weather_token, get_weather)
код функции
def get_weather(message,*args):
try:
r = requests.get(
f"https://api.openweathermap.org/data/2.5/weather?q={message.text}&appid={open_weather_token}&units=metric"
)
data = r.json()
city = data['name']
cur_weather = data['main']['temp']
humidity = data['main']['humidity']
pressure = data['main']['pressure']
wind_speed = data['wind']['speed']
bot.send_message(message.chat.id, str(f'Погода в городе: {city}\nТемпература : {cur_weather}C°\nВлажность
{humidity}%\nДавление {pressure} мм.рт.ст\nВетер: {wind_speed} м/с'))
except Exception as ex:
bot.send_message(message.chat.id, ex)
bot.send_message(message.chat.id, 'Проверьте название города')
Вывод ошибки
Traceback (most recent call last):
File "d:\protonic_bot\bot.py", line 189, in
bot.polling()
File "C:\Users\daMp\AppData\Local\Programs\Python\Python310\lib\site-packages\telebot\__init__.py", line 664, in polling
self.__threaded_polling(non_stop, interval, timeout, long_polling_timeout, allowed_updates)
File "C:\Users\daMp\AppData\Local\Programs\Python\Python310\lib\site-packages\telebot\__init__.py", line 726, in __threaded_polling
raise e
File "C:\Users\daMp\AppData\Local\Programs\Python\Python310\lib\site-packages\telebot\__init__.py", line 686, in __threaded_polling
self.worker_pool.raise_exceptions()
File "C:\Users\daMp\AppData\Local\Programs\Python\Python310\lib\site-packages\telebot\util.py", line 136, in raise_exceptions
raise self.exception_info
File "C:\Users\daMp\AppData\Local\Programs\Python\Python310\lib\site-packages\telebot\util.py", line 88, in run
task(*args, **kwargs)
TypeError: 'str' object is not callable