Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

send_file can't handle link with space and round brackets #4464

Closed
3 tasks done
Orkoliator opened this issue Sep 15, 2024 · 3 comments
Closed
3 tasks done

send_file can't handle link with space and round brackets #4464

Orkoliator opened this issue Sep 15, 2024 · 3 comments

Comments

@Orkoliator
Copy link

Orkoliator commented Sep 15, 2024

Code that causes the issue

async def handle_start_command(event):
message_text, urls = shop_check.get_upcoming_data()
chat_id = event.message.peer_id
if isinstance(chat_id, (PeerUser, PeerChat, PeerChannel)):
await client.send_file(chat_id, urls, caption=message_text)

Expected behavior

Bot should be able to send message with image from url.

Actual behavior

telethon.errors.rpcerrorlist.MediaInvalidError: Media invalid (caused by SendMultiMediaRequest)
I think the reason is that there is a space and round brackets in my image url. I've tried to use "from urllib.parse import quote" but just received another error:
ValueError: Failed to convert quoted_url to media. Not an existing file, an HTTP URL or a valid bot-API-like file ID

Traceback

Traceback (most recent call last):
File "C:\Users\user\tg_bot\tg_bot_venv\Lib\site-packages\telethon\client\updates.py", line 570, in _dispatch_update
await callback(event)
File "C:\Users\user\tg_bot\main.py", line 70, in handle_start_command
await client.send_file(chat_id, urls, caption=message_text)
File "C:\Users\user\tg_bot\tg_bot_venv\Lib\site-packages\telethon\client\uploads.py", line 389, in send_file
result += await self._send_album(
^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\tg_bot\tg_bot_venv\Lib\site-packages\telethon\client\uploads.py", line 504, in _send_album
result = await self(request)
^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\tg_bot\tg_bot_venv\Lib\site-packages\telethon\client\users.py", line 30, in call
return await self._call(self._sender, request, ordered=ordered)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\user\tg_bot\tg_bot_venv\Lib\site-packages\telethon\client\users.py", line 87, in _call
result = await future
^^^^^^^^^^^^
telethon.errors.rpcerrorlist.MediaInvalidError: Media invalid (caused by SendMultiMediaRequest)

Telethon version

1.36.0

Python version

3.12.6

Operating system (including distribution name and version)

Windows 11

Other details

message_text, urls = shop_check.get_upcoming_data()
This method shares string in message_text and list of urls in urls. One of urls happened to have space and round brackets in it.

Checklist

  • The error is in the library's code, and not in my own.
  • I have searched for this issue before posting it and there isn't an open duplicate.
  • I ran pip install -U https://github.com/LonamiWebs/Telethon/archive/v1.zip and triggered the bug in the latest version.
@Orkoliator
Copy link
Author

link to reproduce the issue:
https://cdn1.epicgames.com/salesEvent/salesEvent/EGS_TOEM_SomethingWeMade_S2 (1)_1200x1600-df680f435db3f53c2021e8727e312df7

@Lonami
Copy link
Member

Lonami commented Sep 18, 2024

I don't plan to look into this any time soon. Though, the URL doesn't have an extension, so perhaps the library simply fails to send the proper information.

You can try appending something like #a.jpg or ?a.jpg. The server shouldn't care, but the library would know the type.

Or you can construct the correct input media directly (don't remember exactly how, but it's somewhere in the code).

@Orkoliator
Copy link
Author

The workaround I used is to just download an image with name defined by me and then send it as file.

In my case additional logic to check any link and modify it if it is necessary would be too much.
Thanks for answer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants