如何修复Telethon的异常BadMessageError

时间:2018-07-12 21:46:02

标签: python exception error-handling telethon

我正在做一个应用程序,以从Telegram频道下载所有文件。下载时,我收到错误消息:

telethon.errors.rpcbaseerrors.BadMessageError: Message too old, and it cannot be verified 
whether the server has received a message with this msg_id or not.

有人知道如何解决这个问题吗?

1 个答案:

答案 0 :(得分:1)

我通过此代码测试并下载了所有文件,这很好。 (例如Fundamentos_de_Matemática_Elementar.pdf

from telethon import TelegramClient

api_id = XXXXX
api_hash = 'a191b0c8c7d88a1c34XXXXXXXXXXXXX'
phone_number = '+98937XXXXXXXX'
######################t##########################
channel_username = 'matematicaEmPDF'
################################################

client = TelegramClient(phone_number,
                    api_id,
                    api_hash,        
        )

client.start(phone=phone_number)

# ---------------------------------------
msgs = client.get_messages(channel_username, limit=100)

for msg in msgs.data:
    if msg.media is not None:
        client.download_media(message=msg)