B
B
Batyr1112132021-08-04 20:40:06
Python
Batyr111213, 2021-08-04 20:40:06

Why does it throw the error NameError: name 'message' is not defined?

#Telegram weather bot
from pyowm import OWM
from pyowm.utils.config import get_default_config
import telebot
config_dict = get_default_config()
config_dict['language'] = 'ru'
owm = OWM( '368415eee59e1b1fb5c7d43f321c174d', config_dict )
bot = telebot.TeleBot( "1907544940:AAE8Jgoko2M60uDwHVbdFNLPr4fd8NbolUI")
@bot.message_handler(content_types=['text'])
def send_echo(message):
mgr = owm.weather_manager()
observation = mgr.weather_at_place( message.text )
w = observation.weather
temp = ( w.temperature)('celsius')["temp"]

answer = "City " + message.text + " now " + w.detailed_status + "/n"
answer += "Temperature is around " + str(temp) + "/n/n"

if temp < 10:
answer += "It's cold as fuck right now, dress really warm!".
elif temp < 20:
answer += "It's cold now, dress warmly."
elif temp < 24:
answer += "The weather is fine, dress lightly :)"
elif temp < 29:
answer += "The weather is fucked up, dress for summer"
elif temp > 30:
answer += "It's hot, don't get too much sun "
elif temp > 38:
answer += "Hot cunt, come out tonight"

bot.send_message(message.chat.id, answer)
bot.

File "C:\Python\Telebot.py", line 15, in
answer = "City " + message.text + " now " + w.detailed_status, + "/n"
NameError: name 'message' is not defined

Answer the question

In order to leave comments, you need to log in

1 answer(s)
U
UberPool, 2021-08-04
@UberPool

This error occurs because Python cannot find the message variable.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question