问题描述
我正在尝试使用 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 秒。 这段代码运行良好,但有时几个小时后,尽管尝试了函数,程序还是会出现以下错误。
Telegram is having internal issues RpcCallFailError: Telegram is having internal issues,please try again later. (caused by GetHistoryRequest)
我的问题是如何防止这个错误的发生以及如果发生了如何处理,因为 try except 不起作用。 有人可以帮我吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)