Телеграм бот @util.async() ^^^^^ SyntaxError: invalid syntax

я только начинаю изучать питон и телеграмм ботов. Изначально бот не реагировал на команду /start и ошибка была такая: @dp.message_handlers(commands=["start"]) TypeError: 'Handler' object is not callable

(в мейне при запуске кода работает все правильно)

На форумах (с похожей ошибкой) посоветовали сделать это:

pip3 uninstall PyTelegramBotAPI
pip3 install pyTelegramBotAPI
pip3 install --upgrade pyTelegramBotAPI

После этого появилась вот такая ошибка:

C:\Users\User\Desktop\tw\venv\Scripts\python.exe C:\Users\User\Desktop\tw\main_wtg_bot.py 
Traceback (most recent call last):
  File "C:\Users\User\Desktop\tw\main_wtg_bot.py", line 4, in <module>
    import telebot
  File "C:\Users\User\Desktop\tw\venv\lib\site-packages\telebot\__init__.py", line 816
    @util.async()
          ^^^^^
SyntaxError: invalid syntax

Process finished with exit code 1

(В мейне все так же работает)

Далее код

Main

import requests
import datetime
from pprint import pprint
from config import open_weather_token


def get_weather(city, open_weather_token):
    try:
        r = requests.get(
            f'https://api.openweathermap.org/data/2.5/weather?q={city}&appid={open_weather_token}&units=metric'
            )
        data = r.json()
        ##pprint(data)

        city = data["name"]
        cur_weather = data["main"]["temp"]
        humidity = data["main"]["humidity"]
        pressure = data["main"]["pressure"]
        wind = data["wind"]["speed"]
        sunrise_timestamp = datetime.datetime.fromtimestamp(data["sys"]["sunrise"])
        sunset_timestamp = datetime.datetime.fromtimestamp(data["sys"]["sunset"])
        length_of_the_day = datetime.datetime.fromtimestamp(data["sys"]["sunset"]) - datetime.datetime.fromtimestamp(data["sys"]["sunrise"])

        pprint(f"***{datetime.datetime.now().strftime('%Y-%m-%d %H:%M')}***\n"
              f"Weather in:{city}\n Темп.:{cur_weather}C° \n"
              f" Влажность:{humidity} \n Давление:{pressure} \n"
              f" Ветер:{wind} \n"
              f"Восход:{sunrise_timestamp} Закат:{sunset_timestamp} \n"
              f"Длина дня:{length_of_the_day}"
              )

    except Exception as ex:
        print(ex)
        print('Change city name')


def main():
    city = input('Text ur city')
    get_weather(city, open_weather_token)


if __name__ == '__main__':
    main()

main_wtg_bot

import requests
import datetime
import config
import telebot
from main import get_weather
from config import tg_token, open_weather_token
from aiogram import Bot, types
from aiogram.dispatcher import Dispatcher
from aiogram.utils import executor


bot = Bot(token=tg_token)
dp = Dispatcher(bot)


@dp.message_handlers(commands=["start"])
async def start_command(message: types.Message):
    await message.reply("Hi!", get_weather())


if __name__ == '__main__':
    executor.start_polling(dp)

config

open_weather_token = "Тут мой токен с open weather "
tg_token = "Тут токен бота(у меня были мысли, что ошибка в токене, поэтому проверялось все с двумя ботами)"

Я понятия не имею как это фиксить, поэтому прошу помощи.


Ответы (0 шт):