Answer the question
In order to leave comments, you need to log in
Error when I wrote the code in python, what should I do?
The code:
from pyowm import OWM
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(place)
w = "observation.weather()"
temp = w.temperature('celsius') ["temp"]
answer = "В городе " + place + " сейчас " + w.detailed_status() + "\n"
answer += "Температура сейчас в районе" + str(temp) + "\n\n"
if temp < 10:
answer +=" Сейчас очень холодно, одевайся тепло."
elif temp < 20:
answer +=" Сейчас холодно, одевайся потеплее."
else:
answer +="Температура норм, одевай что угодно."
bot.send_message(message.chat.id, answer)
bot.polling( none_stop = True )
D:\Python>python test2.py
Traceback (most recent call last):
File "D:\Python\test2.py", line 15, in <module>
temp = w.temperature('celsius') ["temp"]
AttributeError: 'str' object has no attribute 'temperature'
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question