【发布时间】:2022-01-21 02:45:57
【问题描述】:
我在 python 上的 telebot 包上编写了电报机器人。
从 2021 年 3 月 1 日开始工作没有问题。该机器人的主要任务是从用户发送的文档中解析信息。它还处理一些命令。所有其他类型的数据都从用户转发给开发者。
2022 年 1 月 17 日,日志中出现了 5 个错误条目:
A request to the Telegram API was unsuccessful. Error code: 502 Description: Bad Gateway
大约一个小时后,用户的每个请求都在日志中返回错误:
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']"
我发现当 bot 尝试使用 download_file() 方法从用户下载发送的文档时出现 403 错误。我的代码中断的部分:
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
机器人在 CentOS 上运行。我尝试了其他工作场所并且问题是实际的。 https://api.telegram.org/file/bot_token/file_path 中的问题。机器人应该成功处理的任何其他类型的消息(照片、贴纸、文本等)。
在 google 上找不到好的解决方案。每天约有 100 名用户使用该机器人。我等不及了,因为它是写在Telegram Bot File Download Suddenly response 403 中的。
我还找到了撤销 API 令牌 https://github.com/eternnoir/pyTelegramBotAPI/issues/581 的解决方案,但之后 403 错误的问题仍然存在。有什么问题?
我使用 PyTelegramBotAPI 4.3.1 版本、Linux Mint 20.2、PyCharm。 我没有找到俄罗斯社区 stackoverflow 的帮助。
附:如果写得不清楚,对不起我的英语
【问题讨论】:
标签: python telegram-bot http-status-code-403