1

我想通过调用getFile方法下载图片文件,这是我使用Telethon(电报客户端 api)的代码:

def get_file_req(client, volume_id, local_id, secret):
    input_file_location = InputFileLocation(volume_id, local_id, secret)
    downloaded_file = client(GetFileRequest(input_file_location, 4000, 2000))
    return downloaded_file

print(get_file_req(client, 434327164, 120080, 1200912808185991895))

我不知道我应该将哪些参数传递给GetFileRequest方法。基于此链接GetFileRequest给出和作为参数location,并提到偏移量必须能被 1KB 整除,但没有一个很好的例子来说明我应该将哪些参数传递给这个方法。当我调用此方法时,我收到此错误:offsetlimit

Traceback (most recent call last):
  File "tclient.py", line 27, in <module>
    print(get_file_req(client, 434327164, 120080, 1200912808185991895))
  File "tclient.py", line 23, in get_file_req
    downloaded_file = client(GetFileRequest(input_file_location, 4000, 2000))
  File "C:\Users\Ali\Desktop\projects\telegram bot dev branch\myenv\Lib\site-packages\telethon\telegram_bare_client.py", line 429, in __call__
    sender, call_receive, update_state, *requests
  File "C:\Users\Ali\Desktop\projects\telegram bot dev branch\myenv\Lib\site-packages\telethon\telegram_bare_client.py", line 517, in _invoke
    raise next(x.rpc_error for x in requests if x.rpc_error)
telethon.errors.rpc_error_list.OffsetInvalidError: (OffsetInvalidError(...), 'The given offset was invalid, it must be divisible by 1KB. See https://core.telegram.org/api/files#downloading-files')
4

1 回答 1

0

我认为使用下载文件的最佳示例telethontelegram_bare_client.py. 看看这里

这是您应该感兴趣的方法:

def download_file(self,
                  input_location,
                  file,
                  part_size_kb=None,
                  file_size=None,
                  progress_callback=None):

向下滚动或搜索并找到它。这是一个很大的函数,它调用了很多其他的自定义函数,这里就不复制代码了。

于 2017-11-11T21:23:28.537 回答