B
B
bybacapitan2022-04-22 00:06:37
Python
bybacapitan, 2022-04-22 00:06:37

How to send a photo using a link in a telegram bot to aiogram?

After reading the documentation, I made the following code:

if "тест" in message.text.lower():
        test = 'ссылка'
        await bot.send_photo(message.chat.id, test)

but it doesn't work and throws this error:
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

tell me what I did wrong.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
sanders rocket, 2022-04-22
@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 )

A
Alexey, 2016-10-19
@rishatss

main - the main program of
say - in this case, consider it just a function that prints three parameters as a sentence

Q
Quad_Tree, 2016-10-19
@Quad_Tree

For me, the code is too simple to explain. Open any Java lessons on the Internet and the first thing they tell you is about main (), methods and lines. You will figure it out very quickly if you have previously programmed in another language.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question