web.py笔记ssl 坑爹

今天又回过神来,准备看看web.py的ssl支持

结果调了半天才出来

 

坑爹1 

中文cookbook地址 http://webpy.org/cookbook/ssl.zh-cn

英文cookbook地址 http://webpy.org/cookbook/ssl

 

中文版只给了一个例子,结果怎么也弄不出来

英文版上却了2个例子,第一个是0.37的 跟中文版那个一样,

另一个是0.36及以前的,说明0.36的可能会出exception(For version 0.36 and earlier (somewhat broken implementation, will crash on SSLException))

但是0.37版还没发布呢。。。。。

 

坑爹2 

 

用0.36版运行0.37的例子

提示 raise ImportError("You must install pyOpenSSL to use HTTPS.")

 

用0.36版运行0.36的例子

提示 找不到cherrypy,没法import

 

我是两个lib都装了

结果进入坑爹3

 

坑爹3 

 

不知道0.36这个例子的path是怎么出来的,好像也不是linux的吧

也不给个说明,我一直以为还有个lib没装,google了半天没结果,到最后重新看代码才发现这2个path有点不对劲

搜素了一下,才在python目录里找到

 

0.36修正后的例子

 

 

import web
from web.wsgiserver import CherryPyWSGIServer
from web.wsgiserver.ssl_builtin import BuiltinSSLAdapter

#ssl_cert = "path/to/ssl_certificate"
#ssl_key = "path/to/ssl_private_key"
ssl_cert = "C:/Python27/Lib/test/ssl_cert.pem"
ssl_key = "C:/Python27/Lib/test/ssl_key.pem"


CherryPyWSGIServer.ssl_adapter = BuiltinSSLAdapter(ssl_cert,ssl_key,None)


urls = ("/.*", "hello")
app = web.application(urls, globals())

class hello:
    def GET(self):
        return 'Hello, world!'

if __name__ == "__main__":
    app.run()
 

 

0.37的例子,未验证,留个记号

import web

from web.wsgiserver import CherryPyWSGIServer

CherryPyWSGIServer.ssl_certificate = "path/to/ssl_certificate"
CherryPyWSGIServer.ssl_private_key = "path/to/ssl_private_key"

urls = ("/.*", "hello")
app = web.application(urls, globals())

class hello:
    def GET(self):
        return 'Hello, world!'

if __name__ == "__main__":
    app.run()
 

 

 

你可能感兴趣的:(web.py)