Answer the question
In order to leave comments, you need to log in
Why doesn't webhook for telegram bot work?
Bot code:
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(), '/', {'/': {}})
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;
}
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"}']
Answer the question
In order to leave comments, you need to log in
Try to install the webhook (Setwebhook) with your hands even through the browser line, then check if it is up, if everything is ok, then comment out the lines:
bot.remove_webhook()
bot.set_webhook(url=' https ://myserver.tk/bot ')
Try so.
What server is the bot on? Home or Dedicated?
Do you have a white IP or domain?
Is the certificate (https) attached to this address?
Similar problem. Server in Germany, worked for more than a year without failures. Trouble since this morning
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"}']
, and no changes were made to the server.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question