首页 > 解决方案 > Telegram is having internal issues RpcCallFailError

问题描述

I'm trying to get the latest message from a telegram channel with telethon and the following code:

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())

I have to use this method due to the delay of about 30 seconds in receiving messages via streaming channels with many members. And this code works well, but sometimes after a few hours, despite the try except function, program gets following error.

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

My question is how to prevent this error from occurring and how to handle it if it occurs, because try except dose not work. Someone can help me?

标签: pythonpython-3.xtelegramtelethon

解决方案


推荐阅读