Skip to content

Instantly share code, notes, and snippets.

@setazer
Last active June 19, 2018 04:39
Show Gist options
  • Save setazer/441df1c243fbba7e770ae1277f105c4a to your computer and use it in GitHub Desktop.
Save setazer/441df1c243fbba7e770ae1277f105c4a to your computer and use it in GitHub Desktop.
Simplest cherrypy server
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