标签: cheroot

如何使用 HTTPS 在 CherryPy WSGI 服务器 (Cheroot) 上运行 Flask 应用程序?

我现在使用 HTTP 在 CherryPy Cheroot WSGI 服务器上运行 Python 2.7 Flask 应用程序,如下所示。

from cheroot.wsgi import Server as WSGIServer
from cheroot.wsgi import PathInfoDispatcher as WSGIPathInfoDispatcher

from MyFlaskApp import app

d = WSGIPathInfoDispatcher({'/': app})
server = WSGIServer(('0.0.0.0', 80), d)

if __name__ == '__main__':
   try:
      server.start()
   except KeyboardInterrupt:
      server.stop()
Run Code Online (Sandbox Code Playgroud)

我需要做什么才能从这里转移到 HTTPS?我找到了以下说明,但它似乎不适用于我的应用程序。

from cheroot.server import HTTPServer
from cheroot.ssl.builtin import BuiltinSSLAdapter

HTTPServer.ssl_adapter = BuiltinSSLAdapter(
        certificate='cert/domain.crt', 
        private_key='cert/domain.key')
Run Code Online (Sandbox Code Playgroud)

我可以将上述示例应用到 Cheroot 上的 Flask 应用程序吗?如果没有,Cheroot 上用于 HTTPS 的 Flask 应用程序的简单示例是什么?

wsgi cherrypy flask python-2.7 cheroot

3
推荐指数
1
解决办法
4547
查看次数

尝试在 CherryPy 服务器上部署 Flask 应用程序

我试图在 CherryPy 服务器上部署我的 Flask 应用程序。我喜欢它的简单和简约的性质。

所以我 PIP'ed CherryPy 如下

pip install CherryPy-15.0.0-py2.py3-none-any.whl
Run Code Online (Sandbox Code Playgroud)

并编写如下脚本-许多来源建议的非常普遍

from cherrypy import wsgiserver
from hello import app

d = wsgiserver.WSGIPathInfoDispatcher({'/': app})
server = wsgiserver.CherryPyWSGIServer(('0.0.0.0', 80), d)

if __name__ == '__main__':
   try:
      server.start()
   except KeyboardInterrupt:
      server.stop()
Run Code Online (Sandbox Code Playgroud)

令我惊讶的是,我有导入错误。经过几次谷歌搜索后,我了解到我必须将导入行更改为 cheroot 才能使其工作。

from cheroot.wsgi import Server
from cheroot.wsgi import PathInfoDispatcher
Run Code Online (Sandbox Code Playgroud)

现在,我的代码运行良好。但是,如果这是使用 CherryPy WSGI 服务器的正确方法,或者我是否使用了错误版本的 CherryPy,我有点困惑。我很困惑,因为 Cheroot 似乎已经超过一岁了(可以追溯到 2014 年),但我在 CherryPy WSGI 服务器上的 Flask 周围找到的所有信息都在使用from cherrypy import wsgiserver,而不是from cheroot.wsgi import Server,甚至是最新的帖子。

这让我不确定我是否在做正确的事情。

有人可以解释一下这种混乱吗?

python cherrypy flask cheroot

2
推荐指数
1
解决办法
5285
查看次数

标签 统计

cheroot ×2

cherrypy ×2

flask ×2

python ×1

python-2.7 ×1

wsgi ×1