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

telethon.errors.rpcerrorlist.LimitInvalidError while iter_download #4390

Open
3 tasks done
lcipria opened this issue Jun 14, 2024 · 3 comments
Open
3 tasks done

telethon.errors.rpcerrorlist.LimitInvalidError while iter_download #4390

lcipria opened this issue Jun 14, 2024 · 3 comments

Comments

@lcipria
Copy link

lcipria commented Jun 14, 2024

Code that causes the issue

client.iter_download(file = message, limit = 1, offset = 983040, request_size = 131072)

Expected behavior

iterate for 1 chunk containing the 131072 bytes after the first 983040 from the file in the message

Actual behavior

telethon.errors.rpcerrorlist.LimitInvalidError: An invalid limit was provided.

Traceback

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 1, in <listcomp>
  File "/home/luciano/.local/lib/python3.10/site-packages/telethon/requestiter.py", line 87, in __next__
    return self.client.loop.run_until_complete(self.__anext__())
  File "/usr/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
    return future.result()
  File "/home/luciano/.local/lib/python3.10/site-packages/telethon/requestiter.py", line 74, in __anext__
    if await self._load_next_chunk():
  File "/home/luciano/.local/lib/python3.10/site-packages/telethon/client/downloads.py", line 66, in _load_next_chunk
    cur = await self._request()
  File "/home/luciano/.local/lib/python3.10/site-packages/telethon/client/downloads.py", line 76, in _request
    result = await self.client._call(self._sender, self.request)
  File "/home/luciano/.local/lib/python3.10/site-packages/telethon/client/users.py", line 87, in _call
    result = await future
telethon.errors.rpcerrorlist.LimitInvalidError: An invalid limit was provided. See https://core.telegram.org/api/files#downloading-files (caused by GetFileRequest)

Telethon version

1.36.0

Python version

3.10.12

Operating system (including distribution name and version)

Ubuntu 22.04.4 LTS

Other details

as documentation:

  • The parameter offset must be divisible by 4 KB.
>>> (983040 / 4096).is_integer()
True
  • The parameter limit must be divisible by 4 KB.
  • 1048576 (1 MB) must be divisible by limit.

P.S.
usingoffset = 1048576 it works

client.iter_download(file = message, limit = 1, offset = 1048576, request_size = 131072)

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.
@Lonami
Copy link
Member

Lonami commented Jun 14, 2024

Most RPC errors come directly from Telegram, and this one is no exception. So I don't think the library will be able to "fix" this.

I don't have plans to look into this any time soon, but it sounds like you've already dug into the code a bit, so you're welcome to experiment calling https://tl.telethon.dev/methods/upload/get_file.html directly and see if it can be made work.

@NotStatilko
Copy link
Contributor

See this #3199

Requirements are slightly different for offset than ones that stated. You will need to use something like my example function from this Issue (pad_request_size) and then truncate result to your desired offset.

@lcipria
Copy link
Author

lcipria commented Jun 17, 2024

to be honest i wrapped the method like this:

    def __iter_download(self, file, offset, limit, request_size):
        n = 0
        for chunk in self.client.iter_download(file = file, offset = offset, request_size = request_size):
            yield chunk
            if (n := n+1) >= limit:
                break

and it works for me...

I guess there's some dark magic involving _load_next_chunk during _request?

P.S. by not manually set "limit", in my case, it will be automatically be set to 37 and the call will be executed.

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

3 participants