Skip to content
Advertisement

A request to the Telegram API was unsuccessful. The server returned HTTP 403 Forbidden

I have the telegram bot written on telebot package on python.

From 03/01/2021 worked without problems. Main task of this bot parse information from documents sent by users. It also handles some commands. All other types of data forward from the user to the developer.

On January 17, 2022, 5 entries with an error appeared in the logs:

A request to the Telegram API was unsuccessful. Error code: 502 Description: Bad Gateway

After about an hour, each request from users returned with an error in the logs:

A request to the Telegram API was unsuccessful. The server returned HTTP 403 Forbidden. Response body:n[b'<html>\r\n<head><title>403 Forbidden</title></head>\r\n<body>\r\n<center><h1>403 Forbidden</h1></center>\r\n<hr><center>nginx/1.18.0</center>\r\n</body>\r\n</html>\r\n']"

I find that a 403 error occurs when bot trying to download the sended document from user with the download_file() method. The part of my code where its breaks:

def handling_documents(message):
    def save_file():
        downloaded_file = bot.download_file(bot.get_file(message.document.file_id).file_path)
        filename = message.document.file_name

The bot runs on CentOS. I tried other workplaces and problem is actual. The problem in https://api.telegram.org/file/bot_token/file_path . Any other types of messages (photos, stickers, text, etc.) the bot handling successfully, as it should.

Couldn’t find a good solution on google. About 100 users use the bot daily. I can’t just wait as it is written in Telegram Bot File Download Suddenly response 403 .

I also found a solution with the revoke of the API token https://github.com/eternnoir/pyTelegramBotAPI/issues/581 But after that the problem with the 403 error remained. What could be wrong?

I use PyTelegramBotAPI 4.3.1 version, Linux Mint 20.2, PyCharm. I didn’t find help by russian community stackoverflow.

P.S. sorry for my english if it written not clear

Advertisement

Answer

It seems like some kind of telegram api bug. The problem resolved itself. Bot recovered after a 2-day downtime.

Advertisement