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.