cyclone(python)是否支持HTTPS连接和SSL?

2024-04-23 17:54:23 发布

您现在位置:Python中文网/ 问答频道 /正文

cyclone(python)是否支持HTTPS连接和SSL?如果是的话,你能举个例子吗?在

我已经看过了cyclone github page上的文档和代码,找不到任何对SSL的引用。但是因为很多旋风都是缠绕在一起的,也许我遗漏了一些东西。。。在


Tags: 代码文档httpsgithubsslpage例子cyclone
2条回答

在我找到这篇文章之后,已经添加了SSL示例。在这里:https://github.com/fiorix/cyclone/tree/master/demos/ssl

README

cyclone is a Twisted protocol, therefore it may be used in conjunction with any other protocol implemented in Twisted.

如果Twisted支持SSL,则cyclone支持它,例如:

#file: cyclone-ssl.py
import cyclone.web

class IndexHandler(cyclone.web.RequestHandler):
    def get(self):
        self.write("hello world")

factory = cyclone.web.Application([(r"/", IndexHandler)])
portstr = "ssl:4443:privateKey=server_key.pem:certKey=server_cert.pem"

# make twisted app
from twisted.application import service, strports

application = service.Application("cyclone-ssl")
strports.service(portstr, factory).setServiceParent(application)

运行方式:

^{pr2}$

激活ssl的部分是portstr。它指定服务器在4443端口上服务,并使用server_key.pem作为其私钥,server_cert.pem作为证书。在

相关问题 更多 >