Forums

Telegram gets timeout error when trying to send bot updates

Hi. I'm using pythonanywhere for hosting a webhook server for a Telegram bot. Apprently Telegram gets a timeout error when trying to send the updates.

enter image description here

A free account only has one worker so, if your web app is busy with another request that takes a long time, the webhook will have to wait for that request to finish before it can be handled.

I have the same issue. I never had any issues until 5 ou 6 days ago. I make the webhook send the request when the app is not busy and it fails instantly.

I just sent a POST request from my local machine to the webhook endpoint and the PythonAnywhere responded, but when I do the same from the Telegram bot, it gets the same error as above.

And this is recent. I've been reading the logs and everything was working fine until between 13 and 15 of this month.

What do you see in your logs? What is your web app doing before the timeout? Do you log anything about it?

My app is a Telegram bot that manages a channel and is idle most of the time.

The app is basically the following: We have a react app hosted at Vercel which the users send some data to a Telegram channel via PythonAnywhere. At the channel, the bot handles some users text commands, sending them to Pythonanywhere via Webhooks. The first part is working fine, but the latter stopped working recently. This app has been working for nearly one year.

I log every JSON based POST request, which are sent by Telegram's webhook. I noticed that after the date I mentioned, my app didn't received any requests from the webhook, even when the users interact with the bot. Telegram's getWebhookInfo shows there are nearly 30 requests queued though.

What do you see in your access log? Do you see incoming requests?

No incoming requests since 15 Oct.

If there are no requests logged, then the most likely cause is that they are not reaching PythonAnywhere. Check the address that you're using for the webhook.

I just tested the webhook using https://webhook.site/ and I just received all queued requests at the same time. Now, I changed it back to the correct PythonAnywhere's endpoint and got the same "Connection timed out" error again.

So, I believe something has changed in PythonAnywhere's roughly a week ago that is now blocking requests coming from Telegram.

Yeah, this problem is fairly recent for me too. It appears somewhere between Telegram and PythonAnywhere, the request gets blocked. Has PythonAnywhere received any requests from Telegram in recent days? I see no trace of the request in access.log or error.log.

Specifically, requests from Telegram to PythonAnywhere are blocked somewhere before arriving at the app.

However, requests from PythonAnywhere to Telegram are working fine since I use both.

Is it possible to use Cloudflare as a reverse proxy for PythonAnywhere? This could potentially solve the problem

You can't use Cloudflare with a free account, no -- you need control over the domain name used for the site in order to set up the proxying, and of course that's not possible with a website at foo.pythonanywhere.com.

Perhaps you could get in touch with Telegram and try to get more details from them about whether they're queuing stuff up? I appreciate that they're a large organisation so it might be hard to get in touch with a real person there...

Well, after some testing and tweaking, I've found the solution to this problem is to migrate to another host, which in my case is fly.io.

Everything is working fine again.

im having the same problem on paid and free account since this time. what has happened?

What IPs are the telegram requests coming from?

i can't figured out, but now my bot is working on the free and on the paid account. have you done smth?

curl https://api.telegram.org/botXXXX/getWebhookInfo {"ok":true,"result":{"url":"https://talipova.pythonanywhere.com/XXXX/","has_custom_certificate":false,"pending_update_count":0,"max_connections":40,"ip_address":"XXXXX"}

No, we did not change anything.

after 2 working weeks, i've received this error again:

has_custom_certificate":false,"pending_update_count":4,"last_error_dat e":1669878021,"last_error_message":"Connection timed out","max_connections":40

this is absolute mysticism

Have you tried using a custom domain on your paid account? We're wondering whether telegram could be queueing requests for all PythonAnywhere subdomains together.

yes, i've tried, but it also doesn't work and I have disabled my subscription (because of that). My bot is still not working

Is there any way to find out from Telegram what IP addresses it is using to send the requests?

Unfortunately, I have the same issue. Few days my bot worked correctly, then pythonanywhere stops receiving updates from Telegram. Error log is empty but there are no corresponding (to the post requests that telegram sends) records in access log. Is there any solution? Here is what information I get if receive getWebhookInfo: Info

Thanks for any help

Unfortunately I think that all we can recommend here is that you get in touch with Telegram tech support, if that's at all possible. If nothing is appearing in the access logs for your site, it means that they're just not sending the messages, and only they will know why that is.

Hi Guys!

Same with me. From the access log, I don't see Telegram sending the POST to PythonAnywhere:

1:

{'url': 'XXX, 'has_custom_certificate': False, 'pending_update_count': 5, 'last_error_date': 1674624788, 'last_error_message': 'Connection timed out', 'max_connections': 40, 'ip_address': '35.173.69.207'}

2:

tl_bot.getWebhookInfo()

{'url': 'XXX', 'has_custom_certificate': False, 'pending_update_count': 6, 'last_error_date': 1674625033, 'last_error_message': 'Connection timed out', 'max_connections': 40, 'ip_address': '35.173.69.207'}

3:

print(tl_bot.getWebhookInfo())

{'url': 'XXX', 'has_custom_certificate': False, 'pending_update_count': 6, 'last_error_date': 1674625064, 'last_error_message': 'Connection timed out', 'max_connections': 40, 'ip_address': '35.173.69.207'}

If there's nothing in the access log, Telegram is probably not sending those messages for some reason. You could check with their support, as Giles suggested above.

Did anyone manage to solve this issue or was able to get in touch with the Telegram support?

I have the same problem with my Telegram bot which didn't receive any updates since a week ago. I did not make any recent changes to the code and a second bot running on the same Pythonanywhere account with almost the same code is still working fine.

According to the access log I received the last update from Telegram on January 28th from the IP 91.108.6.48. The second bot (the one that is still working) receives his updates from the IP 91.108.6.144.

If I manually call the getWebhookInfo endpoint from the Telegram bot API I get the same as the thread opener (Connection timed out).

I already tried the following without success:

  • deleting the webhook and setting it again (deleteWebhook and setWebhook)
  • temporarily changing the URL
  • revoking the API key

Since a few days my bot is receiving updates from Telegram on the webhook, so everything is working fine again. I wrote to the support a while ago but didn't get any reply, so I don't know if they fixed something manually or if the problem resolved "by itself".

Thanks for sharing that with us!

It's happening again.

Looks like you need to talk to ask telegram.

Hi, i have the same problem . Three weeks ago it began to recieve updates again but it's been two days that i face the same problem & i've tried to contact telegram but they didn't reply. i think there is a serious problem between pythonanywhere servers & Telegram. i'm afraid there is nothing that we users can do about this problem so HELP needed from pythonanywhere staff. Thanks in advance.

It does not look alike anything we can do about it. We do not block it.

The problem happened to me again too. Since a few days, my bot is not receiving updates anymore. What is interesting is that it is again the same instance as last time. My second bot running as a second web app on Pythonanywhere is still working fine.

If telegram is not sending the request, then there is not really anything we can do to help.

@glenn I fully understand that, but I think it is still very helpful to share this kind of issues with other users. I was glad to find this post because it meant that I was not the only one with this issue and it made it less likely that the problem was in my code :)

Since one or two days I'm receiving updates again, so let's hope that it's now working again for good.

The problem happened to me too! Wow, glad to know I'm not the only one. I have been working on the problem for hours. The only thing stange to me was that if I created a compeletly new bot and used it's token then everything worked fine. But, when I reverted back to my usual bot token (even after revoking the token) I got the 'Connection timed out' error.

Looks like the problem is on telegram side of things.

Same problem here... The only weird thing i see is that the last access logs are GET methods from pythonanywhere (probably).

After that, nothing. Telegram webhook info says connection timedout

3.90.184.78 - - [05/May/2023:08:55:35 +0000] "GET / HTTP/1.1" 404 233 "-" "python-requests/2.28.1" "3.90.184.78" response-time=0.652 3.90.184.78 - - [05/May/2023:08:57:39 +0000] "GET / HTTP/1.1" 404 233 "-" "python-requests/2.28.1" "3.90.184.78" response-time=0.013 3.90.184.78 - - [05/May/2023:09:02:32 +0000] "GET / HTTP/1.1" 404 233 "-" "python-requests/2.28.1" "3.90.184.78" response-time=0.021 52.200.142.75 - - [05/May/2023:09:07:26 +0000] "GET / HTTP/1.1" 404 233 "-" "python-requests/2.28.1" "52.200.142.75" response-time=0.056

Are you using a custom domain, or a PythonAnywhere subdomain? One theory we have at this point is that a bug on Telegram's side makes them think that all subdomains of PythonAnywhere.com are actually the same site, so if there is a problem with one they incorrectly say that all of them are timing out.

I did not change anything, and the bot just suddenly works again 2 days after it originally stopped working

Yeah sound like something out of our control. Glad it's working now though

I have your problem right now)

As mentioned above, our best guess right now is that Telegram have a bug where they treat all sites with hostnames like something.pythonanywhere.com as if they were the same, so if one times out due to a bug, they will stop delivering messages to all of them. Unfortunately there's nothing we can do about that; you'd need to raise it with Telegram.