@bybacapitan

Как отправить фото с помощью ссылки в телеграм боте на aiogram?

Прочитав документацию сделал такой код:
if "тест" in message.text.lower():
        test = 'ссылка'
        await bot.send_photo(message.chat.id, test)

но он не работает и выдает такую ошибку:
Task exception was never retrieved
future: <Task finished name='Task-22' coro=<Dispatcher._process_polling_updates() done, defined at C:\Users\артем\AppData\Local\Programs\Python\Python310\lib\site-packages\aiogram\dispatcher\dispatcher.py:407> exception=InvalidHTTPUrlContent('Failed to get http url content')>
Traceback (most recent call last):
  File "C:\Users\артем\AppData\Local\Programs\Python\Python310\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 415, in _process_polling_updates
    for responses in itertools.chain.from_iterable(await self.process_updates(updates, fast)):
  File "C:\Users\артем\AppData\Local\Programs\Python\Python310\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 235, in process_updates
    return await asyncio.gather(*tasks)
  File "C:\Users\артем\AppData\Local\Programs\Python\Python310\lib\site-packages\aiogram\dispatcher\handler.py", line 116, in notify
    response = await handler_obj.handler(*args, **partial_data)
  File "C:\Users\артем\AppData\Local\Programs\Python\Python310\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 256, in process_update
    return await self.message_handlers.notify(update.message)
  File "C:\Users\артем\AppData\Local\Programs\Python\Python310\lib\site-packages\aiogram\dispatcher\handler.py", line 116, in notify
    response = await handler_obj.handler(*args, **partial_data)
  File "C:\Users\артем\Desktop\bot\main1.py", line 259, in text
    await bot.send_photo(message.chat.id, ssilka)
  File "C:\Users\артем\AppData\Local\Programs\Python\Python310\lib\site-packages\aiogram\bot\bot.py", line 527, in send_photo
    result = await self.request(api.Methods.SEND_PHOTO, payload, files)
  File "C:\Users\артем\AppData\Local\Programs\Python\Python310\lib\site-packages\aiogram\bot\base.py", line 231, in request
    return await api.make_request(await self.get_session(), self.server, self.__token, method, data, files,
  File "C:\Users\артем\AppData\Local\Programs\Python\Python310\lib\site-packages\aiogram\bot\api.py", line 140, in make_request
    return check_result(method, response.content_type, response.status, await response.text())
  File "C:\Users\артем\AppData\Local\Programs\Python\Python310\lib\site-packages\aiogram\bot\api.py", line 115, in check_result
    exceptions.BadRequest.detect(description)
  File "C:\Users\артем\AppData\Local\Programs\Python\Python310\lib\site-packages\aiogram\utils\exceptions.py", line 140, in detect
    raise err(cls.text or description)
aiogram.utils.exceptions.InvalidHTTPUrlContent: Failed to get http url content

подскажите что я сделал не так.
  • Вопрос задан
  • 3505 просмотров
Пригласить эксперта
Ответы на вопрос 1
rocketmachine
@rocketmachine
from aiogram.types import URLInputFile
image = URLInputFile(
    "https://www.python.org/static/community_logos/python-powered-h-140x182.png",
    filename="python-logo.png"
)
await bot.send_photo(message.chat.id, image )
Ответ написан
Ваш ответ на вопрос

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

Похожие вопросы