Ошибка aiogram 3.0.0b6

import asyncio
import logging
from aiogram import html
from aiogram import Bot, Dispatcher, types
from aiogram.filters import Command, CommandObject
from datetime import datetime
from aiogram.types import ContentType

logging.basicConfig(level=logging.INFO)

bot = Bot(token='BOT-TOKEN', parse_mode='HTML')
dp = Dispatcher()

@dp.message(types.ContentType.TEXT)
async def extract_data(message: types.Message):
    data = {
        "url": "<N/A>",
        "email": "<N/A>",
        "code": "<N/A>"
    }
    entities = message.entities or []
    for item in entities:
        if item.type in data.keys():
            data[item.type] = item.extract(message.text)
        await message.reply(
            "Вот что я нашел:\n"
            f"URL: {html.quote(data['url'])}\n"
            f"E-mail: {html.quote(data['email'])}\n"
            f"Пароль: {html.quote(data['code'])}"
        )


async def main():
    await dp.start_polling(bot, mylist=list[str])

if __name__ == '__main__':
    asyncio.run(main())

Сама ошибка:

Traceback (most recent call last):
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\inspect.py", line 1285, in getfullargspec
    sig = _signature_from_callable(func,
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\inspect.py", line 2392, in _signature_from_callable
    raise TypeError('{!r} is not a callable object'.format(obj))
TypeError: 'text' is not a callable object

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "D:\Python Lessons\aiogram\python-lesson\main.py", line 15, in <module>
    async def extract_data(message: types.Message):
  File "D:\Python Lessons\aiogram\python-lesson\venv\lib\site-packages\aiogram\dispatcher\event\telegram.py", line 127, in wrapper
    self.register(callback, *filters, flags=flags)
  File "D:\Python Lessons\aiogram\python-lesson\venv\lib\site-packages\aiogram\dispatcher\event\telegram.py", line 75, in register
    filters=[FilterObject(filter_) for filter_ in filters],
  File "D:\Python Lessons\aiogram\python-lesson\venv\lib\site-packages\aiogram\dispatcher\event\telegram.py", line 75, in <listcomp>
    filters=[FilterObject(filter_) for filter_ in filters],
  File "<string>", line 5, in __init__
  File "D:\Python Lessons\aiogram\python-lesson\venv\lib\site-packages\aiogram\dispatcher\event\handler.py", line 71, in __post_init__
    super(FilterObject, self).__post_init__()
  File "D:\Python Lessons\aiogram\python-lesson\venv\lib\site-packages\aiogram\dispatcher\event\handler.py", line 29, in __post_init__
    self.spec = inspect.getfullargspec(callback)
  File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\inspect.py", line 1295, in getfullargspec
    raise TypeError('unsupported callable') from ex
TypeError: unsupported callable

Помогите новичку, пожалуйста


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

Автор решения: biflé

Aiogram ругается на твой фильтр - TYPES.CONTENTTYPE.TEXT. Он думает, что ты передал ему функцию, хотя то что ты ей дал функцией не является. Правильно здесь будет сделать так: @dp.message(content_types=Types...). По край ней мере, в двойке это точно заработает, насчёт aiogram 3 - не уверен.

→ Ссылка
Автор решения: makerscript

То что у тебя на 14 строке замени с @dp.message(types.ContentType.TEXT) на @dp.message_handler(Command("команда"))

пример : /команда

→ Ссылка