Z
Z
Zenettany2020-06-09 11:24:52
Python
Zenettany, 2020-06-09 11:24:52

Error in code, what am I doing wrong?

When I try to run it, I get an error:
File "telegram.py", line 30
expect:
^
SyntaxError: invalid syntax
Here is the code itself:

from pyowm import OWM
import time
from pyowm.utils.config import get_default_config
config_dict = get_default_config()
config_dict['language'] = 'ru'  
import telebot

owm = OWM('api')
bot = telebot.TeleBot("token")

@bot.message_handler(func=lambda m: True)
def send_echo(message):
  try:
    mgr = owm.weather_manager()
    observation = mgr.weather_at_place( message.text )
    w = observation.weather
    temp = w.temperature('celsius')["temp"]
    owm.weather_at_place(place)
  
    answer = "В городе " + message.text + " сейчас " + w.detailed_status + "\n" 
    answer += "Температура сейчас в районе " + str(temp) + "\n\n"
    if temp < 0:
      answer += "Сейчас ппц как холодно, одевайся как капуста."
    elif temp < 20:
      answer += "Сейчас прекрасная погодка, одевай что хочешь"
    else:
      answer += "Сейчас ппц как жарко, можешь идти в майке и шортах."

    bot.send_message(message.chat.id, answer)
  expect:
    bot.send_message(message.chat.id, 'Ошибка! Город не найден!')
bot.polling( none_stop = True )

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
agutin, 2020-06-09
@Zenettany

Line 30: not expect, but except
Exception, not expectation))

B
bbkmzzzz, 2020-06-09
@bbkmzzzz

Do not catch ALL exceptions, it is not clear what exactly happened. Handle specific, well, or at least do this:

except Exception as e:
    print(e, e.args, file=sys.stderr)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question