Telegram through telethon timeouts on my server. FloodWaitError keeps multiplying on a script that works fine on local

huangapple go评论58阅读模式
英文:

Telegram through telethon timeouts on my server. FloodWaitError keeps multiplying on a script that works fine on local

问题

应用在我的个人电脑上运行正常,没有超时。当我将其关闭以将其移到服务器上时,首次在使用电话号码、密码和登录代码登录会话后,出现了以下错误:

telethon.errors.rpcerrorlist.FloodWaitError: 需要等待 31387 秒(由 ResolveUsernameRequest 引起)

在以下代码行:

client.get_messages(channel_name, ids=141)

我等待的时间远远超过了约 8 小时。

我的个人电脑上的程序一直正常运行。我再次停止它并在服务器上运行相同的脚本。

现在等待时间加倍:

telethon.errors.rpcerrorlist.FloodWaitError: 需要等待 67203 秒(由 ResolveUsernameRequest 引起)

在相同的代码行上。无法使用。

这是我自己的频道,由我登录的帐户拥有,我收到这条消息...

英文:

The application works fine on my PC. No timeouts. When I turned it off to move it to my server, at first after logging into the session with phone number, password, and login code, this error appeared:

telethon.errors.rpcerrorlist.FloodWaitError: A wait of 31387 seconds is required (caused by ResolveUsernameRequest)

on line

client.get_messages(channel_name, ids=141)

I waited way longer than the ~8+ hours.

My PC program was working fine. I again stopped it and opened the same script on my server.

Now the wait is doubled:

telethon.errors.rpcerrorlist.FloodWaitError: A wait of 67203 seconds is required (caused by ResolveUsernameRequest)

on same line. Unusable.

This is MY OWN channel owned by the very account I sign in to that I'm getting the message from...

答案1

得分: 1

你的问题标题提到你“无法登录”,但你的问题正文似乎表明情况并非如此。我将假设你的问题是问题正文中描述的情况。

Telethon将使用.session文件作为缓存,其中包含用户名及其对应的idaccess_hash等信息。这两个值都是作为API请求的参数使用时所需的。

如果用户名不在缓存中,库将需要首先获取它。这个获取操作会有一个较长的洪水等待时间,无法绕过。

在这种情况下,正确的方法是:

print(await client.get_input_entity(channel_name))

一次,然后在你的脚本中将输出硬编码,如下所示:

from telethon import types

CHANNEL = types.InputPeerChannel(channel_id=..., access_hash=...)

(你可以使用不同的机制来持久存储它。硬编码只是最简单的方法。)

然后你可以使用CHANNEL代替channel_name

英文:

Your question title mentions you "can't login", but your question body seems to indicate otherwise. I will assume your problem is what's described in the question's body.

Telethon will use the .session file as a cache, containing, among other things, usernames and their corresponding id and access_hash. Both of these values are required to use a chat as a parameter for the API requests.

If the username is not in cache, the library will need to fetch it first. This fetching has a high flood wait, and there's no way to bypass that.

The correct approach here would be to:

print(await client.get_input_entity(channel_name))

once, and then hardcode the output in your script, like so:

from telethon import types

CHANNEL = types.InputPeerChannel(channel_id=..., access_hash=...)

(You can use a different mechanism to store it persistently. Hardcoding it is just the simplest way to do it.)

And then you can use CHANNEL instead of channel_name.

huangapple
  • 本文由 发表于 2023年3月9日 23:11:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/75686499.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定