【问题标题】:HTTPs over Bottlepy and Gevent基于 Bottlepy 和 Gevent 的 HTTPs
【发布时间】:2016-03-14 14:40:29
【问题描述】:

在此代码中插入 HTTP 的最佳方法是什么? 我需要使用 Bootlepy 和 Gevent,就像这个例子一样。 谢谢

from gevent import monkey; monkey.patch_all()

from time import sleep
from bottle import route, run

@route('/hello')
def hello():
    return "<html><body>hello</body></html>"

@route('/stream')
def stream():
    yield 'START'
    sleep(3)
    yield 'MIDDLE'
    sleep(5)
    yield 'END'

run(host='0.0.0.0', port=8080, server='gevent')

【问题讨论】:

  • 在 HTTPS (TLS) 到达您的应用程序之前终止它,例如 Nginx/HAProxy。那你就不用担心了。使用不同的 WSGI 服务器失败。 CheeryPy 和 Gunicorn 都支持 SSL。抱歉,我对 Bottle 不熟悉,但可能有一个我看不到的选项。

标签: python https gevent


【解决方案1】:
from gevent import pywsgi
import bottle

# Get bottle's WSGI callable
wsgi_app = bottle.default_app()

# Needs a generated SSL key and certificate to use.
server = pywsgi.WSGIServer(('0.0.0.0', 443), wsgi_app,
                           keyfile='server.key', certfile='server.crt')
server.serve_forever()

【讨论】:

  • 不起作用:(我使用以下命令生成证书:openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout ./cert.key -out ./cert.crt。但我有这个错误:dropbox.com/s/8whglsosxhorp9v/…
猜你喜欢
  • 1970-01-01
  • 2013-01-04
  • 2019-03-30
  • 2015-07-28
  • 2012-06-13
  • 2014-02-26
  • 2011-11-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多