python-ImportError:无法导入名称wsgiserver

问题描述 投票:0回答:1

运行针对网络的python脚本时出现以下错误

    Traceback (most recent call last):
      File "SampleWSTest.py", line 10, in <module>
        from web.wsgiserver.ssl_builtin import BuiltinSSLAdapter
      File "C:\Python27\lib\site-packages\web\wsgiserver\ssl_builtin.py", line 14, in <module>
        from cherrypy import wsgiserver
    ImportError: cannot import name wsgiserver

在python 2.7.15上运行

import web
import sys
import argparse
import traceback
from web.wsgiserver import CherryPyWSGIServer
from web.wsgiserver.ssl_builtin import BuiltinSSLAdapter
from OpenSSL import SSL

class Healthcheck:
    def GET(self):
        return 'Yassssssssss !!!!!'

URLS = ('/svc/healthcheck', 'Healthcheck')

CherryPyWSGIServer.ssl_certificate = 'alice.crt'
CherryPyWSGIServer.ssl_private_key = 'alice.key'

if __name__ == '__main__':
    CherryPyWSGIServer.ssl_adapter = BuiltinSSLAdapter(CherryPyWSGIServer.ssl_certificate, CherryPyWSGIServer.ssl_private_key)
    CherryPyWSGIServer.ssl_adapter.context = SSL.Context(SSL.SSLv23_METHOD)
    CherryPyWSGIServer.ssl_adapter.context.set_options(SSL.OP_NO_SSLv3)
    CherryPyWSGIServer.ssl_adapter.context.use_certificate_file(CherryPyWSGIServer.ssl_certificate)
    CherryPyWSGIServer.ssl_adapter.context.use_privatekey_file(CherryPyWSGIServer.ssl_private_key)
    app = web.application(URLS, globals())
    app.run()

此操作在我们不得不禁用ssl 2ssl 3之后开始失败,因此不得不添加ssl_adapter,但是BuiltinSSLAdapter导入失败。如果还有其他选择,请提出建议。基本上是想先禁用ssl 2ssl 3,而我们之前没有from web.wsgiserver.ssl_builtin import BuiltinSSLAdapterfrom OpenSSL import SSL

python python-2.7 ssl cherrypy cherrypywsgiserver
1个回答
1
投票
[CherryPy在2017年将wsgiserver移至cheroot。

http://docs.cherrypy.org/en/latest/history.html#v9-0-0

所以现在您需要像这样导入它:

from cheroot.wsgi import Server as CherryPyWSGIServer

或在整个过程中重命名。
© www.soinside.com 2019 - 2024. All rights reserved.