@F1ury

Ошибка в aiogram :'cannot import name 'executor' from 'aiogram'', почему?

import logging
from aiogram import Bot, Dispatcher, executor, types
import requests
import json

# Telegram bot token
API_TOKEN = "___TELEGRAM_API_TOKEN___"

# Configure logging
logging.basicConfig(level=logging.INFO)

# Initialize bot and dispatcher
bot = Bot(token=API_TOKEN)
dp = Dispatcher(bot)

print("!BOT STARTED!")

# Message handler that sends greeting when bot started
@dp.message_handler(commands=['start', 'help'])
async def send_welcome(message: types.Message):
    """
    This handler will be called when user sends `/start` or `/help` command
    """
    await message.reply("Probiv Bot Template by DimonDev: @dimondevchat")


# This is the main probiv function that returns a json and formats it, then sends it
@dp.message_handler(content_types=['text'])
async def text(message: types.Message):

    # Get the message text and interpret it as a phone number
    nomer = message.text
    print(nomer)

    # The endpoint for the probiv API that passes as a query the phone number
    url = "https://dimondevosint.p.rapidapi.com/main?phone=" + nomer

    # Necessary headers for the API to work
    head = {
        # RapidAPI necessary host header
        "X-RapidAPI-Host": "dimondevosint.p.rapidapi.com",
        # API key that you can get by subscribing to the API
        "X-RapidAPI-Key": "___RAPIDAPI_API_KEY___"
    }

    # Send the request with all the parameters and print the result for debugging
    response = requests.request("GET", url, headers=head)
    print(response.text)

    # Load the data of the response into a JSON object
    data = json.loads(response.text)

    # Send the formatted data to the user on Telegram
    await bot.send_message(message.chat.id,f"""
                           
                            ФИО: {data['name']}
                           ️ Страна: {data['country']}
                            Оператор: {data['operator']}
                            Объявления: {data['obyavleniya']}

                         


# Main loop
if __name__ == '__main__':
    executor.start_polling(dp, skip_updates=True)


В терминале выдает ошибку:

ImportError: cannot import name 'executor' from 'aiogram' (C:\Users\F1ury\AppData\Local\Programs\Python\Python312\Lib\site-packages\aiogram\__init__.py)
  • Вопрос задан
  • 142 просмотра
Пригласить эксперта
Ответы на вопрос 2
Vindicar
@Vindicar
RTFM!
Под какую версию aiogram код, и какая версия установлена у тебя? aiogram изменил API при переходе с версии 2 на версию 3.
Ответ написан
Комментировать
febday
@febday
Установи pip install aiogram==2.25.1
Но учти, то данная версия aiogram не поддерживает текущую версию Telegram Bot API. Для этого есть aiogram 3 или моя библиотека, но её я скидывать не буду (если что сам найдёшь), потому что сделаю форк позже
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы