Last active
June 19, 2018 04:39
-
-
Save setazer/441df1c243fbba7e770ae1277f105c4a to your computer and use it in GitHub Desktop.
Simplest cherrypy server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cherrypy, requests | |
WEBHOOK_LISTEN = '127.0.0.1' | |
WEBHOOK_PORT = 12345 | |
WEBHOOK_URL_PATH = "/test/" | |
cherrypy.config.update({ | |
'server.socket_host': WEBHOOK_LISTEN, | |
'server.socket_port': WEBHOOK_PORT, | |
'engine.autoreload.on': False | |
}) | |
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") | |
print(json_string) | |
# update = telebot.types.Update.de_json(json_string) | |
# # Эта функция обеспечивает проверку входящего сообщения | |
# bot.process_new_updates([update]) | |
return 'Brave new world' | |
# else: | |
# raise cherrypy.HTTPError(403) | |
if __name__ == "__main__": | |
cherrypy.quickstart(WebhookServer(), WEBHOOK_URL_PATH, {'/': {}}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment