避免在Python中泛滥

发布于 2025-01-19 13:48:06 字数 586 浏览 3 评论 0原文

我是 Pyrogram 的新手,我尝试制作订阅机器人

,我想在任何满足我的过滤器的消息时立即发送消息,但每次我连续发送超过 3 条消息时,我都会收到 FloodWait 错误。捕获那个异常是没有问题的,但是它总是变大

15 -> 60->第333章-> 417秒

我该如何避免?每条消息后睡几秒钟并没有帮助。我在文档中没有找到任何有关确切估计等待时间的信息

            for user in subs_arr:
                try:
                    app.send_message(user, msg)
                    time.sleep(10)
                except pyrogram.errors.exceptions.flood_420.FloodWait as wait_err:
                    wait_err = str(wait_err)
                    time.sleep(wait_err.x)

I am new to Pyrogram and I try to make subsctiption bot

I want to send messages as soon as any satisfy my filters, but every time I send more than 3 messages in a row I get FloodWait error. There is no problem in catching that exception, but it is always getting bigger

15 -> 60 -> 333 -> 417 seconds

How can I avoid it? Sleeping for some seconds after every message doesn't help. And I didn't find anything about exact estimated waiting time in docs

            for user in subs_arr:
                try:
                    app.send_message(user, msg)
                    time.sleep(10)
                except pyrogram.errors.exceptions.flood_420.FloodWait as wait_err:
                    wait_err = str(wait_err)
                    time.sleep(wait_err.x)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

掐死时间 2025-01-26 13:48:06

经过一番研究,我发现无法避免洪水处理:D

,但我对时间的理解完全错误。我在该机器人的机器上使用了pyrargram,我不需要它的异步组件
然而,机器人需要异步睡眠,我在这种方式上重新加工时遇到了问题。最后,我想出了该解决方案(现在睡觉通常是< = 60秒)

try:
     await app.send_message(user, msg)
     await asyncio.sleep(3)
except pyrogram.errors.exceptions.flood_420.FloodWait as wait_err:
     await asyncio.sleep(wait_err.x)
except TimeoutError:
     continue
except pyrogram.errors.exceptions.bad_request_400.UsernameNotOccupied:
                    continue

希望它会帮助某人,甚至有人会建议我更好的方法

After some research I found that there is no way to avoid FloodWait :D

But I had totally wrong understanding of time.sleep. I used Pyrogram for that bot, bot I didn't need async component of that
Nevertheless bot requires asynchronous sleep and I had problems with reworking it this way. Finally I came up with that solution (now sleep usually is <=60 second)

try:
     await app.send_message(user, msg)
     await asyncio.sleep(3)
except pyrogram.errors.exceptions.flood_420.FloodWait as wait_err:
     await asyncio.sleep(wait_err.x)
except TimeoutError:
     continue
except pyrogram.errors.exceptions.bad_request_400.UsernameNotOccupied:
                    continue

Hope it'll help somebody or even somebody will advice me better way of doing this

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文