【发布时间】:2023-02-18 07:15:14
【问题描述】:
我们尝试使用 1 个电报客户端从频道列表中连续流式传输消息,然后将消息生成到 kafka。然后我们有第二个电报客户端来使用消息并使用 client.download_media() 下载相关媒体(照片/视频)。我们的问题是,这仅在客户端 1 和 2 相同时有效,但在它们是不同帐户时无效。我们不确定这是否与会话文件或访问哈希有关,还是其他原因?
是否可以支持我们的用例?我们试图解决的主要问题是异步媒体下载可能会导致大量积压,如果我们的服务器死机,积压可能会消失。这就是为什么我们首先要将消息放入 kafka 进行短期存储。如果您有更好的建议,也将不胜感激。
这是制作方
async with client:
messages = client.iter_messages(channel_id, limit=10)
async for message in messages:
print(message)
if message.media is not None:
# orig_media = message.media
# converted_media = BinaryReader(bytes(orig_media)).tgread_object()
# print('orig, media', orig_media)
# print('converted media', converted_media)
message_bytes = bytes(message) #convert to bytes
producer.produce(topic, message_bytes)
这是不同客户端的消费者端
with self._client:
#telethon.errors.rpcerrorlist.FileReferenceExpiredError: The file reference has expired and is no longer valid or it belongs to self-destructing media and cannot be resent (caused by GetFileRequest)
try:
self._client.loop.run_until_complete(self._client.download_media(orig_media, in_memory))
except Exception as e:
print(e)
【问题讨论】:
-
来自官方文档,
The file download operation may return a FILE_REFERENCE_EXPIRED error (or another error starting with FILE_REFERENCE_): in this case, the file_reference field of the input location must be refreshed。请查看this link。