我想通过调用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
方法。基于this link,GetFileRequest
提供location
,offset
和limit
作为参数,并提到偏移量必须可以被1 KB整除,但是没有一个很好的示例显示我应该将哪些参数传递给此方法。当我调用此方法时,我收到此错误:
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')
答案 0 :(得分:0)
我认为使用telethon
下载文件的最佳示例是telegram_bare_client.py
。看看它here。
这是您应该感兴趣的方法:
def download_file(self,
input_location,
file,
part_size_kb=None,
file_size=None,
progress_callback=None):
向下滚动或搜索并找到它。它是一个很大的功能,可以调用许多其他自定义函数,因此我不会在这里复制代码。