bottle on cherrypy server + ssl

zyash picture zyash · Apr 30, 2012 · Viewed 7.3k times · Source

I am trying to run Bottle on top of Cherrypy's server. I want to get SSL Support.

So far I have tried this:

from bottle import Bottle, route
from cherrypy import wsgiserver

app = Bottle()

@app.route("/")
def index():
  return "Hello"


server = wsgiserver.CherryPyWSGIServer(
            ('0.0.0.0', 443), app)

server.ssl_adapter.private_key = 'server.key'
server.ssl_adapter.certificate = 'server.crt'
server.start()

But the above throws an ArgumentError that I can't set properties on a None object (ssl_adpater). Apparently I need to set the ssl_adapter property to some object that derives from SSLAdapter, but I couldn't find any examples.

I am using Python 2.7 and Cherrypy 3.2.2

Thanks.

Answer

BluesRockAddict picture BluesRockAddict · Apr 30, 2012

Try using the following:

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"

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