【问题标题】:aiogram.utils.exceptions.WrongFileIdentifier: Wrong file identifier/http url specifiedaiogram.utils.exceptions.WrongFileIdentifier:指定了错误的文件标识符/http url
【发布时间】:2021-02-10 06:23:17
【问题描述】:

我想制作一个机器人,您可以向该机器人发送文件的链接,它会向您发送文件,但我从标题中收到错误消息。我也尝试发送 InputFile 对象,但没有发送任何内容。这是我的代码

from aiogram import Bot, types
from aiogram.dispatcher import Dispatcher
from aiogram.utils import executor
from aiogram.types.input_file import InputFile
 
bot = Bot(token = '')
dp = Dispatcher(bot)
 
@dp.message_handler()
async def send_playlist(message: types.Message):
    print(message.text)
    await bot.send_document(message.chat.id, message.text)
 
executor.start_polling(dp)

这是完整的错误文本

future: <Task finished name='Task-14' coro=<Dispatcher._process_polling_updates() done, defined at B:\portable_soft\python\lib\site-packages\aiogram\dispatcher\dispatcher.py:331> exception=WrongFileIdentifier('Wrong file identifier/http url specified')>
Traceback (most recent call last):
  File "B:\portable_soft\python\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 339, in _process_polling_updates
    for responses in itertools.chain.from_iterable(await self.process_updates(updates, fast)):
  File "B:\portable_soft\python\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 194, in process_updates
    return await asyncio.gather(*tasks)
  File "B:\portable_soft\python\lib\site-packages\aiogram\dispatcher\handler.py", line 117, in notify
    response = await handler_obj.handler(*args, **partial_data)
  File "B:\portable_soft\python\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 214, in process_update
    return await self.message_handlers.notify(update.message)
  File "B:\portable_soft\python\lib\site-packages\aiogram\dispatcher\handler.py", line 117, in notify
    response = await handler_obj.handler(*args, **partial_data)
  File "B:\portable_soft\adb\file_bot.py", line 12, in send_playlist
    await bot.send_document(message.chat.id, message.text)
  File "B:\portable_soft\python\lib\site-packages\aiogram\bot\bot.py", line 402, in send_document
    result = await self.request(api.Methods.SEND_DOCUMENT, payload, files)
  File "B:\portable_soft\python\lib\site-packages\aiogram\bot\base.py", line 201, in request
    return await api.make_request(self.session, self.__token, method, data, files,
  File "B:\portable_soft\python\lib\site-packages\aiogram\bot\api.py", line 104, in make_request
    return check_result(method, response.content_type, response.status, await response.text())
  File "B:\portable_soft\python\lib\site-packages\aiogram\bot\api.py", line 78, in check_result
    exceptions.BadRequest.detect(description)
  File "B:\portable_soft\python\lib\site-packages\aiogram\utils\exceptions.py", line 136, in detect
    raise err(cls.text or description)
aiogram.utils.exceptions.WrongFileIdentifier: Wrong file identifier/http url specified```

【问题讨论】:

  • 在问题中添加错误信息。
  • @dev-aentgs 完成

标签: telegram-bot


【解决方案1】:

根据您的问题,我不太明白您要做什么。如果您更好地描述您的用例,我可能会建议一些更有用的东西。你想用播放列表做什么?

Here is one way to work with files:

@dp.message_handler(regexp='(^cat[s]?$|puss)')
async def cats(message: types.Message):
    with open('data/cats.jpg', 'rb') as photo:
        '''
        # Old fashioned way:
        await bot.send_photo(
            message.chat.id,
            photo,
            caption='Cats are here ?',
            reply_to_message_id=message.message_id,
        )
        '''

        await message.reply_photo(photo, caption='Cats are here ?')

我实际上更喜欢使用 FileID,但我不确定这是否会对您有所帮助。

【讨论】:

  • 这个函数叫做“send_playlist”,因为我是从另一个项目中拿来的。我没有需要发送的文件,我有指向它的链接
  • 尝试显式传递参数,像这样:bot.sendDocument(chatid='xxxxx', document='yyy.com/zzzz", ... ) 等等dev-docs.aiogram.dev/api/methods/send_document
猜你喜欢
  • 1970-01-01
  • 2018-04-10
  • 2017-07-30
  • 2018-09-13
  • 1970-01-01
  • 2017-02-22
  • 2023-03-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多