Qwentor
@Qwentor
Веб-программист

Почему не работает вебхук для телеграм бота?

Код бота:
import cherrypy
import telebot

BOT_TOKEN = "bot:token"

bot = telebot.TeleBot(BOT_TOKEN)

@bot.message_handler(commands=["start"])
def command_start(message):
    bot.send_message(message.chat.id, "Привет! Я бот номер 1")

class WebhookServer(object):
    @cherrypy.expose
    def index(self):
        length = int(cherrypy.request.headers['content-length'])
        json_string = cherrypy.request.body.read(length).decode("utf-8")
        update = telebot.types.Update.de_json(json_string)
        bot.process_new_updates([update])
        return ''

if __name__ == '__main__':
    bot.remove_webhook()
    bot.set_webhook(url='https://myserver.tk/bot')
    cherrypy.config.update({
        'server.socket_host': '127.0.0.1',
        'server.socket_port': 7771,
        'engine.autoreload.on': False
    })
    cherrypy.quickstart(WebhookServer(), '/', {'/': {}})


nginx:
location /bot {
    proxy_pass         http://127.0.0.1:7771/;
    proxy_redirect     off;
    proxy_set_header   Host $host;
    proxy_set_header   X-Real-IP $remote_addr;
    proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header   X-Forwarded-Host $server_name;
  }


И ничего, на /start не реагирует
Через какое-то время валится с ошибкой:

telebot.apihelper.ApiException: A request to the Telegram API was unsuccessful. The server returned HTTP 504 Gateway Time-out. Response body:
[b'{"ok":false,"error_code":504,"description":"Gateway Timeout"}']
  • Вопрос задан
  • 2126 просмотров
Решения вопроса 1
@T3h_Vermili0n
Попробуйте руками хоть через строку браузера установить вебхук (Setwebhook), затем проверьте встал ли он, если все ок, то закомментируйте строки:
bot.remove_webhook()
bot.set_webhook(url='https://myserver.tk/bot')
Попробуйте так.
Ответ написан
Пригласить эксперта
Ответы на вопрос 2
Бот стоит на каком сервере? Домашнем или выделенном?
Есть белый айпи или домен?
Сертификат (https) к этому адресу привязан?
Ответ написан
@ximik666
Аналогичная проблема. Сервер в Германии, проработал больше года без сбоев. С сегодняшнего утра проблема
A request to the Telegram API was unsuccessful. The server returned HTTP 504 Gateway Time-out. Response body:
[b'{"ok":false,"error_code":504,"description":"Gateway Timeout"}']
, причем на сервере никаких изменений не проводилось.
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы