Search code examples
pythonweb-servicessslbottlegevent

How to implement TLS/SSL for python Bottle using Gevent


  • Hi, I am using Bottle python module for my web server.
  • I use monkey.patch_all() function from gevent to implement concurrency.
  • My server is working perfectly.
  • But now i need to implement TLS/SSL for my web server.

I found many ways of implementing it using CherryPy module.

But I need to implement it without using CherryPy or any other module.

Is there any way to add TLS by using Bottle and Gevent?

Here is a sample code of what I tried.

server.py :

from bottle import route, run,request
from gevent import monkey; monkey.patch_all()
import time

valur = 0

@route('/hello/<name>', method = 'GET')
def index(name):
    print valur
    time.sleep(9)
    return str(valur)

run(host='0.0.0.0', port=5000, reloader =False,interval=10, server='gevent')

Solution

    • I found a simple solution for this problem after series of exploration.
    • By just adding the private key and certificate file location in the server we can enable TLS\SSL support to your server.

    The modified sorce code is given below,

    run(host='0.0.0.0', port=5000, reloader =False,interval=10, server='gevent', certfile='server.crt', keyfile='server.key')