Telegram 存在内部问题 RpcCallFailError

问题描述 投票:0回答:1

我正在尝试通过 telethon 和以下代码从电报频道获取最新消息:

import t_api,time,asyncio
from telethon import TelegramClient
from telethon.tl.functions.messages import GetHistoryRequest
async def get_message():
    license_b="allow"
    flag=0
    try:
        async with TelegramClient(t_api.username,t_api.api_id,t_api.api_hash) as client:
            my_channel=await client.get_entity("channel_name")
            while license_b=="allow":
                history=await client(GetHistoryRequest(peer=my_channel,offset_id=0,offset_date=None,add_offset=0,limit=1,max_id=0,min_id=0,hash=0))
                t1=history.messages[0].message
                if flag==0:
                    sub_t1=t1
                    flag+=1
                if sub_t1!=t1:
                    flag=0
                    checking_b(t1)
                time.sleep(2)
    except:
        return False
asyncio.run(get_message())

由于会员较多的流媒体频道接收消息大约有30秒的延迟,所以我不得不使用此方法。 这段代码运行良好,但有时几个小时后,尽管有 try except 函数,程序仍会出现以下错误。

Telegram is having internal issues RpcCallFailError: Telegram is having internal issues, please try again later. (caused by GetHistoryRequest)

我的问题是如何防止此错误发生以及发生时如何处理,因为 try except 不起作用。 有人可以帮助我吗?

python python-3.x telegram telethon
1个回答
0
投票

这是因为你直接使用 time.sleep(2) 而发生的。而是使用这个

import asyncio

await asyncio.sleep(2)

希望能解决问题。

© www.soinside.com 2019 - 2024. All rights reserved.