LonamiWebs / Telethon

Pure Python 3 MTProto API Telegram client library, for bots too!
https://docs.telethon.dev
MIT License
9.68k stars 1.38k forks source link

Trouble with uploading file from URL using client.send_file() #1415

Closed ghost closed 4 years ago

ghost commented 4 years ago

Checklist

Code that causes the issue

await bot.client.send_file(
                        bot.chat_id,
                        "https://storage.googleapis.com/paperplaneextdf.appspot.com/track.flac",
                        caption="Uploaded succesfully",
                        force_document=False,
                        allow_cache=False,
                        reply_to=bot.id)

Traceback

Traceback info:
Traceback (most recent call last):
  File "/home/dragonightfury/Документы/paperplaneextdf/userbot/events.py", line 59, in wrapper
    await func(check)
  File "/home/dragonightfury/Документы/paperplaneextdf/userbot/modules/evaluators.py", line 224, in spotify_downloader
    await bot.client.send_file(
  File "/usr/lib/python3.8/site-packages/telethon/client/uploads.py", line 351, in send_file
    msg = self._get_response_message(request, await self(request), entity)
  File "/usr/lib/python3.8/site-packages/telethon/client/users.py", line 74, in __call__
    result = await future
telethon.errors.rpcerrorlist.MediaEmptyError: The provided media object is invalid or the current account may not be able to send it (such as games as users) (caused by SendMediaRequest)

Where my journey begins: I was trying to upload a .flac track with metadata. What did I try: hachoir, a bunch of FTP storages (i was able to get direct link to a file), Google Firebase, local storage. Google Firebase is the only one service that provides common direct link. I thought this problem was caused by FTP, but when i have set up Google Firebase and uploaded my file there, i got the same traceback. Uploading from local storage works fine, but without metadata.You can check that URL works by yourself.

Thanks for help, best wishes.

Lonami commented 4 years ago

Telethon passes the URL to Telegram servers. If the Telegram servers cannot handle it, then well, there's not much we can do. You can set the attributes= to include the metadata manually if Telegram doesn't infer it. Nothing to do here.

ghost commented 4 years ago

Can i include track cover to attributes? Because i only see lenght/title etc. BTW, maybe you can accept this as a feature request

Lonami commented 4 years ago

Never tried setting a thumb for web files, may or may not work. If the API supports it and Telethon doesn't make it possible, feature requests are welcome, but the API has to support it.