H
H
HELP_PLS2018-08-25 22:13:14
Python
HELP_PLS, 2018-08-25 22:13:14

tg bot doesn't start on webhooks?

I make a bot in a cart (trying)
on ​​win 10
ssl I make
a key and put the certificate in the same folder
5b81a9fdcabe8996707427.png

import telebot
import cherrypy
import config
    
WEBHOOK_HOST = '37.73.147.137'
WEBHOOK_PORT = 80  # 443, 80, 88 или 8443 (порт должен быть открыт!)
WEBHOOK_LISTEN = '0.0.0.0'  
    
WEBHOOK_SSL_CERT = './webhook_cert.pem'  
WEBHOOK_SSL_PRIV = './webhook_pkey.pem'  
    
WEBHOOK_URL_BASE = "https://%s:%s" % (WEBHOOK_HOST, WEBHOOK_PORT)
WEBHOOK_URL_PATH = "/%s/" % (config.token)
    
bot = telebot.TeleBot(config.token)
    
class WebhookServer(object):
    @cherrypy.expose
    def index(self):
        if 'content-length' in cherrypy.request.headers and \
                        'content-type' in cherrypy.request.headers and \
                        cherrypy.request.headers['content-type'] == 'application/json':
            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 ''
        else:
            raise cherrypy.HTTPError(403)
    
@bot.message_handler(func=lambda message: True, content_types=['text'])
def echo_message(message):
    bot.reply_to(message, message.text)
    
bot.remove_webhook()
    
# Ставим заново вебхук
bot.set_webhook(url=WEBHOOK_URL_BASE + WEBHOOK_URL_PATH,
                            certificate=open(WEBHOOK_SSL_CERT, 'r'))

cherrypy.config.update({
        'server.socket_host': WEBHOOK_LISTEN,
        'server.socket_port': WEBHOOK_PORT,
        'server.ssl_module': 'builtin',
        'server.ssl_certificate': WEBHOOK_SSL_CERT,
        'server.ssl_private_key': WEBHOOK_SSL_PRIV
})
     
cherrypy.quickstart(WebhookServer(), WEBHOOK_URL_PATH, {'/': {}})

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
AlmazKayum, 2018-08-30
@AlmazKayum

OSError.
First advice: check the path to the certificates.
In Windows I don’t rummage, but it looks like Linux, and not like in Windows.

V
Val, 2018-09-04
@Desem

1. Make sure the web server is working on your wine machine (firewalls, antivirus, etc.)
2. If you are in Russia, then RKN?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question