ssl python -导入错误:无法导入名称wsgiserver

vq8itlhq  于 2022-11-14  发布在  Python
关注(0)|答案(1)|浏览(127)

运行用于Web的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

iszxjhcz

iszxjhcz1#

CherryPy在2017年将wsgiserver移到了cheroot。
http://docs.cherrypy.dev/en/latest/history.html#v9-0-0
因此,现在您需要像这样导入它:

from cheroot.wsgi import Server as CherryPyWSGIServer

或在整个文件中对其进行重命名。

相关问题