Не понмаю, почему код выдает ошибку

Рейтинг: -1Ответов: 1Опубликовано: 24.03.2023

Есть код на python с спользованием aiogram. Не понимаю, почему он выдает ошибку

    @dp.message_handler(content_types=[types.ContentType.DOCUMENT])
async def echo_doc(message: types.Message):
    await bot.send_document(message.from_user.id, document=message.document.file_id)

@dp.message_handler(content_types=[types.ContentType.PHOTO])
async def echo_picture(message: types.Message):
    await bot.send_photo(message.from_user.id, photo=message.photo[-1].file_id)

@dp.message_handler(content_types=[types.ContentType.ANIMATION])
async def echo_picture(message: types.Message):
    await bot.send_animation(message.from_user.id, animation=message.animation.file_id)

@dp.message_handler()
async def echo_picture(message: types.Message):
    await bot.send_animation(message.from_user.id, message.text)

executor.start_polling(dp)

Ошибка:aiogram.utils.exceptions.BadRequest: Wrong remote file identifier specified: wrong padding in the string

Ответы

▲ 0Принят
#незачем использовать три разных хендлера для doc, photo and animation.
#конечно если вам удобнее, то делайте как хотите
#не обязательно использовать types.ContentType.PHOTO(VIDEO) и тд.
#достаточно весь ваш контент уместить в кавычки, или в список доступных для хендлера типов контента
@dp.message_handler(content_types=['document', 'photo', 'animation']) 
async def echo_files(message: types.Message):
    if(message.document):
        await bot.send_document(message.from_user.id, document=message.document.file_id)
    if(message.photo):
        await bot.send_photo(message.from_user.id, photo=message.photo[-1].file_id)
    if(message.animation):
        await bot.send_animation(message.from_user.id, animation=message.animation.file_id)
#Ошибка выходила по причине неправильного использования send_animation, документацию ниже прилагаю.
#Опять же исходя из документации, я спокойно смог отправить по url первое фото из интернета.
@dp.message_handler()
async def echo(message: types.Message):
    await bot.send_animation(message.from_user.id, "https://cdn.tvc.ru/pictures/o/225/578.jpg")

sendAnimation

sendAnimation2