eternnoir / pyTelegramBotAPI

Python Telegram bot api.
GNU General Public License v2.0
8.11k stars 2.03k forks source link

429, Too Many Requests despite very few messages? #1928

Closed dizzydes closed 1 year ago

dizzydes commented 1 year ago

Is anyone else just setting a webhook on their web server like so (you'll notice I'm not calling remove_webhook():

bot = telebot.TeleBot(TOKEN)
bot.set_webhook(url=WEBHOOK_URL + WEBHOOK_PATH)

Sometimes I get the error too many requests to Telegram API. I've looked at other similar issues but in my case I'm sending and receiving v few messages as its still in dev, certainly not more than 1/second. So I guess that's because when my webserver restarts during debugging or because GCP (App Engine) is switching workers it re-runs the set_webhook? Or could one pending message hit my server too many times? Or something else?

As I'm running this on a web server long polling is not an easy option. But likewise the guidance I've been given on how to maintain a connection without re-running 'set_webhook' is also quite loose "sometimes it'll clear the webhook when there's a bug etc etc" so I'm not sure how to put logic around it or cache it.

Has anyone else had to deal with this and what's the best way?

Is there a simple way to put an if(current_webhook) condition around this as one does to prevent too many disconnect and reconnections to DB? Thanks

Django on Python 3.10

Badiboy commented 1 year ago

Not an issue. Discussion is enough.

dizzydes commented 1 year ago

@Badiboy fair, but if the cause isn't clear shouldn't it be an issue? This package is web-app ready in theory and I'm not sending an excessive amount of requests?

Perhaps it looks like more of a discussion as I pondered potential causes but I don't know the reason...

coder2020official commented 1 year ago

Everything has a limit. You don't get 429 error for just sending lots of messages.

coder2020official commented 1 year ago

There are other reasons I mean.

dizzydes commented 1 year ago

@coder2020official Thanks for your response, and I see, but I'm not doing anything with Telegram except setting webhook. Also, default Django and web server architecture is common enough that I figured this should be breaking for everyone if it doesn't work with it?

(In other words, if something about how Django runs is causing too many requests just from setting webhook).

coder2020official commented 1 year ago

setWebhook also has limits, you can't use it too often. Limit is unspecified though

azhiv commented 3 months ago

@dizzydes Did you manage to solve the issue?