Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
can';t在web.py-python2.7中创建ssl会话_Python_Python 2.7_Ssl_Web.py - Fatal编程技术网

can';t在web.py-python2.7中创建ssl会话

can';t在web.py-python2.7中创建ssl会话,python,python-2.7,ssl,web.py,Python,Python 2.7,Ssl,Web.py,我正在尝试使我的服务器使用https/ssl连接。我有证书和钥匙。 我尝试在中使用该示例,但它仍然使用http而不是https。我的web.py版本是最新的(0.38),但我也尝试使用网站中提供的旧实现,这导致了错误: Traceback (most recent call last): File "/path/server.py", line 7, in <module> from web.wsgiserver.ssl_builtin import BuiltinSSLAdapte

我正在尝试使我的服务器使用https/ssl连接。我有证书和钥匙。 我尝试在中使用该示例,但它仍然使用http而不是https。我的web.py版本是最新的(0.38),但我也尝试使用网站中提供的旧实现,这导致了错误:

Traceback (most recent call last):
File "/path/server.py", line 7, in <module>
from web.wsgiserver.ssl_builtin import BuiltinSSLAdapter
File "/Library/Python/2.7/site-packages/web/wsgiserver/ssl_builtin.py", line 14, in <module>
from cherrypy import wsgiserver
ImportError: cannot import name wsgiserver
有解决办法吗?(我想不是因为这个错误,因为它是由一个适用于web.py较旧版本的使用引起的,而是第一个实现)

谢谢

编辑: 我正在运行的代码:

import sys
import web
from web.wsgiserver import CherryPyWSGIServer

from utils.tools import Tools

from pages.index import index
from pages.search import search
from pages.update_location import update_location
from pages.add_sn_tracking import add_sn_tracking
from pages.edit_sn_tracking import edit_sn_tracking
from pages.add_sheet_tracking import add_sheet_tracking
from pages.edit_sheet_tracking import edit_sheet_tracking


class WebServer:
    def __init__(self):
        CherryPyWSGIServer.ssl_certificate = r"/Volumes/wlutils/Users/TesterUs/snserver/server.crt"
        CherryPyWSGIServer.ssl_private_key = r"/Volumes/wlutils/Users/TesterUs/snserver/server.key"

        self.urls = (
            '/', 'index',
            '/search', 'search',
            '/update_location', 'update_location',
            '/add_sn_tracking', 'add_sn_tracking',
            '/edit_sn_tracking', 'edit_sn_tracking',
            '/add_sheet_tracking', 'add_sheet_tracking',
            '/edit_sheet_tracking', 'edit_sheet_tracking',
        )
        # web.config.debug = False
        self.app = web.application(self.urls, globals())
        self.app.run()

if __name__ == "__main__":
     w = WebServer()

要为SSL设置web.py,只需设置内部CherryPyWSGIServer:

from web.wsgiserver import CherryPyWSGIServer
CherryPyWSGIServer.ssl_certificate = "/file/my.crt"
CherryPyWSGIServer.ssl_private_key = "/file/my.key"
在调用
app=web.application(URL,globals())
之前执行此操作。如果这对您不起作用,让我们来探讨一下,而不是您正在尝试的v.0.38之前的解决方案,它已知不适用于当前的
web.py


后续:似乎正在使用较旧版本的
web.py
。一旦更新到0.38+,示例就成功了。

要为SSL设置web.py,只需设置内部CherryPyWSGIServer:

from web.wsgiserver import CherryPyWSGIServer
CherryPyWSGIServer.ssl_certificate = "/file/my.crt"
CherryPyWSGIServer.ssl_private_key = "/file/my.key"
在调用
app=web.application(URL,globals())
之前执行此操作。如果这对您不起作用,让我们来探讨一下,而不是您正在尝试的v.0.38之前的解决方案,它已知不适用于当前的
web.py


后续:似乎正在使用较旧版本的
web.py
。一旦更新到0.38+,这个例子就成功了。

只是检查——你没有使用nginx或apache前置web.py,对吗?没错,只有web.py只是检查——你没有使用nginx或apache前置web.py,对吗?没错,只有web.py这是我一开始尝试的,它只是创建了一个常规的http会话,请显示示例代码。文档化的解决方案可以工作,因此我们需要您提供更多信息来了解不同之处。您更新的代码似乎工作正常(剪切粘贴)。您应该开始启动,
https://0.0.0.0:8080/
,服务器正在侦听的地址。如果你得到了一些不同的东西,也许可以检查一下你正在使用的web.py的版本。你是对的!出于某种原因,我在/usr/local/libs中安装了更新版本的web.py,在/Libraries中安装了旧版本的web.py。当我在库中更新web.py时,一切都正常。谢谢,太好了!(因为我没有答案了。)这是我一开始尝试的,它只是创建了一个常规http会话。请显示示例代码。文档化的解决方案可以工作,因此我们需要您提供更多信息来了解不同之处。您更新的代码似乎工作正常(剪切粘贴)。您应该开始启动,
https://0.0.0.0:8080/
,服务器正在侦听的地址。如果你得到了一些不同的东西,也许可以检查一下你正在使用的web.py的版本。你是对的!出于某种原因,我在/usr/local/libs中安装了更新版本的web.py,在/Libraries中安装了旧版本的web.py。当我在库中更新web.py时,一切都正常。谢谢,太好了!(因为我没有答案了。)