E
E
EbaRG2021-08-23 15:18:51
Python
EbaRG, 2021-08-23 15:18:51

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 )


Mistake:

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'


I understand that the error is in str, but I don’t know how to fix it, who knows, help and preferably in more detail, I just started learning Python, according to this video ( https://www.youtube.com/watch?v=fp5-XQFr_nk )
Time -code - 54:43

(telegram bot with weather)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Igor, 2021-08-23
@EbaRG

w = "observation.weather()"

extra quotes
, but try to at least understand what you are copy-pasting, it's not just "some words"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question