Ошибка - TypeError: 'str' object is not callable
Начал изучение Python, не смог найти здесь ошибку TypeError: 'str' object is not callable
from pyowm import OWM
from pyowm.utils import config
from pyowm.utils import timestamps
from pyowm.utils.config import get_default_config
config_dict = get_default_config()
config_dict['language']="ru"
import telebot
owm = OWM('токен')
mgr = owm.weather_manager()
bot = telebot.TeleBot("токен")
@bot.message_handler(content_types=['text'])
def send_echo(message):
observation = mgr.weather_at_place(message.text)
w = observation.weather
temp = w.temperature('celsius')['temp']
answer = "В городе " + message.text + " сейчас " + w.detailed_status() + "\n\n"
answer += "Температура сейчас в районе " + str(temp) + "\n\n"
if temp >= -20:
answer += "На улице очень холодно, одевай шубу!!"
elif temp < -10:
answer += "На улице прохладно, одевайся теплее!"
else:
answer += "На улице не очень холодно, одевайся как хочешь"
bot.send_message(message.chat.id, answer)
bot.polling( none_stop = True)
Ответы (1 шт):
Автор решения: MazZz3R
→ Ссылка
Судя по документации (get started) w.detailed_status не функция, а параметр, поэтому к ней обращаться не надо:
answer = "В городе " + message.text + " сейчас " + w.detailed_status + "\n\n"
Исправленный код с русским языком
from pyowm import OWM
from pyowm.utils import config
from pyowm.utils import timestamps
from pyowm.utils.config import get_default_config
config_dict = get_default_config()
config_dict['language']="ru"
import telebot
owm = OWM('токен', config_dict)
mgr = owm.weather_manager()
bot = telebot.TeleBot("токен")
@bot.message_handler(content_types=['text'])
def send_echo(message):
observation = mgr.weather_at_place(message.text)
w = observation.weather
temp = w.temperature('celsius')['temp']
answer = "В городе " + message.text + " сейчас " + w.detailed_status + "\n\n"
answer += "Температура сейчас в районе " + str(temp) + "\n\n"
if temp >= -20:
answer += "На улице очень холодно, одевай шубу!!"
elif temp < -10:
answer += "На улице прохладно, одевайся теплее!"
else:
answer += "На улице не очень холодно, одевайся как хочешь"
bot.send_message(message.chat.id, answer)
bot.polling( none_stop = True)