Skip to content
This repository has been archived by the owner on Jun 2, 2019. It is now read-only.

Too many requests, retry after 1 #165

Closed
Xinayder opened this issue Sep 25, 2016 · 14 comments
Closed

Too many requests, retry after 1 #165

Xinayder opened this issue Sep 25, 2016 · 14 comments

Comments

@Xinayder
Copy link

I updated my bot code, and updated the dependencies as well.
After updating, my bot, hosted on OpenShift, will constantly crash with:

* Running on http://127.10.121.129:8080/ (Press CTRL+C to quit)
 * Restarting with stat
Traceback (most recent call last):
  File "app.py", line 177, in <module>
    bot.setWebhook('https://pymariachi-xinayder.rhcloud.com/hook')
  File "/var/lib/openshift/574af7692d5271961e00014d/python/virtenv/venv/lib/python3.3/site-packages/telepot/__init__.py", line 634, in setWebhook
    return self._api_request('setWebhook', _rectify(p))
  File "/var/lib/openshift/574af7692d5271961e00014d/python/virtenv/venv/lib/python3.3/site-packages/telepot/__init__.py", line 398, in _api_request
    return api.request((self._token, method, params, files), **kwargs)
  File "/var/lib/openshift/574af7692d5271961e00014d/python/virtenv/venv/lib/python3.3/site-packages/telepot/api.py", line 131, in request
    return _parse(r)
  File "/var/lib/openshift/574af7692d5271961e00014d/python/virtenv/venv/lib/python3.3/site-packages/telepot/api.py", line 123, in _parse
    raise e(description, error_code, data)
telepot.exception.TooManyRequestsError: ('Too Many Requests: retry after 1', 429, {'error_code': 429, 'parameters': {'retry_after': 1}, 'ok': False, 'description': 'Too Many Requests: retry after 1'})

I tried contacting Telegram's bot support, but they said I was setting the callback multiple times, when I am not (or I think so). In case anyone's interested, here's my code

I don't know why this is happening. Everything is the same since I last updated my bot.

@GaryBeez
Copy link
Contributor

I'm also having the same error, started on Sept 23rd out of nowhere. My bot is hosted on Heroku, and the error happened even when I specified to use Telepot 8.3

setWebhook() with no arguments raises no exception
Manual setWebhook with curl sets it successfully
Long-polling raises no exception
The same error happens if I use the token for my test bot that is offline most of the time

In the end I set the webhook manually and commented out the command in my code. Is the webhook something you can just set and forget? (unless, of course, you change hosts or bot token)

@Xinayder
Copy link
Author

I managed to fix it by importing time and setting it to sleep before each setWebhook call.

@GaryBeez
Copy link
Contributor

GaryBeez commented Sep 27, 2016

Did you have bot.setWebhook() immediately followed by bot.setWebhook('url')?
I had it in my code from this Heroku sample (#96). So it could be that this was all simply a server-side change to limit webhooking spam on Telegram.

@Xinayder
Copy link
Author

Xinayder commented Sep 28, 2016

No, I had the empty one being called before setting the URL. I have updated my code, in case you want to take a look

@GaryBeez
Copy link
Contributor

Oops, sorry, I was too focused on the problem and forgot that you posted your code.
But that's what I meant, an empty setWebhook, and next line one setting the URL. I also had it like yours, without any sleep between calls.
So it seems the error is just Telegram implementing a limit for the rate you can set (and unset) webhooks.

@nickoala
Copy link
Owner

nickoala commented Sep 28, 2016

Hi guys, thanks for diagnosing the problem. I first thought it had something to do with my setting retries=3 in urllib3 since 9.0. Relieved to see that the problem lies somewhere else.

Out of pure curiosity, why do you need setWebhook() before setWebhook(url)? Telegram seems completely ok with you changing URLs like this:

>>> bot.setWebhook('https://k.whatever.org/abc')
True
>>> bot.setWebhook('https://k.whatever.org/abcde')
True

It seems there's no need to unset it before setting it. Since this is very obvious, I am sure you guys have some reason to do it. Please enlighten me.

@GaryBeez
Copy link
Contributor

Initially I had the bot running locally with long-polling Then when researching how to make it work on Heroku, I found the Heroku Sample code I mentioned above, and it had the lines

BOT.setWebhook() # unset if was set previously
BOT.setWebhook(URL + SECRET)

I just never questioned it and also included it in my code, since I am still a complete newbie when it comes to connectivity in apps.

@Xinayder
Copy link
Author

Xinayder commented Sep 28, 2016

Same for me, I saw the Heroku example and it cleared the webhook before setting it again, so I added it to my code.

Anyways, what's the issue? Is it with Telegram or the API code?

@nickoala
Copy link
Owner

Ok, so it seems this line is NOT needed:

bot.setWebhook()

To set webhook URL, you only need this line:

bot.setWebhook(URL + secret)

And you can forget about all those time.sleep(...).

I seldom use webhook myself, so the above comment is only as far as I can see.

@Noammac
Copy link

Noammac commented Sep 30, 2016

I still get the error. I'm hosting on Heroku and my code is

bot.message_loop({'chat': on_get_message}, source=UPDATE_QUEUE)


@app.route(SECRET, methods=['POST', 'GET'])
def pass_update():
    UPDATE_QUEUE.put(request.data)
    return 'OK'

sleep(5)
bot.setWebhook(URL + SECRET)

(added more than the two last lines for context since it might be wrong)
I still get the error although I tried to sleep() before the setWebhook() and before the setWebhook(URL + SECRET), and some other variations of setWebhook() and sleep()

@leninmedeiros
Copy link

@Noammac any news? I'm facing the same here

@Noammac
Copy link

Noammac commented Oct 18, 2016

Nope. Not a single change, the bots work for one second before erroring and
dying

On Tue, 18 Oct 2016 15:10 Lenin Medeiros, [email protected] wrote:

@Noammac https://github.com/Noammac any news? I'm facing the same here


You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub
#165 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ASpZqx6oT4tD_5Eu4quq2L2Q-eu05CfCks5q1LdEgaJpZM4KF6yD
.

b0g3r added a commit to b0g3r/nosleepbot that referenced this issue Oct 25, 2016
@b0g3r
Copy link

b0g3r commented Oct 25, 2016

same problem:
heroku, setWebhook and TooManyRequests
UPD:
Okay, I solved the problem. Default Gunicorn runs several workers: https://devcenter.heroku.com/articles/python-gunicorn and is set in WEB_CONCURRENCY
If this method is not apptopriate, then you can use the following code:

if webhook_url != bot.getWebhookInfo()['url']:
    bot.setWebhook(webhook_url)

@Noammac
Copy link

Noammac commented Oct 25, 2016

I erased the setWebhook line and committed it, and it worked! The bit
responds to messages and I can see it logging in the console.

On Tue, 25 Oct 2016 17:47 Dmitriy Boger, [email protected] wrote:

same problem:
heroku, setWebhook and TooManyRequests


You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub
#165 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ASpZq86Vz9A_YO_tnZgd02Wn1d_X8gEbks5q3hZzgaJpZM4KF6yD
.

MartinoMensio added a commit to MartinoMensio/polito-aule-bot that referenced this issue Sep 7, 2017
MartinoMensio added a commit to MartinoMensio/polito-aule-bot that referenced this issue Sep 7, 2017
MartinoMensio added a commit to MartinoMensio/polito-aule-bot that referenced this issue Sep 7, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants