librelist archives

« back to archive

Re: [flask] Is there a way of serving HTTPS in Flask? -- SOLUTION

Re: [flask] Is there a way of serving HTTPS in Flask? -- SOLUTION

From:
0byte
Date:
2013-04-27 @ 17:01
For the record:

How to serve HTTPS *directly* from Flask (great for debugging), no nginx, 
no apache, no gunicorn. Just plain Flask:
create a SSL context (http://werkzeug.pocoo.org/docs/serving/)

from OpenSSL import SSL
context = SSL.Context(SSL.SSLv23_METHOD)
context.use_privatekey_file('yourserver.key')
context.use_certificate_file('yourserver.crt')

then

app.run(host='127.0.0.1',port='12344', debug = False/True, ssl_context=context)

There is a confirmed bug in pyOpenSSL that generates a runtime error:
https://bugs.launchpad.net/pyopenssl/+bug/900792

The workaround is to put these 2 lines in werkzeug/serving.py
in class BaseWSGIServer(HTTPServer, object):
...
 def shutdown_request(self,request): 
        request.shutdown()

enjoy,
0

____________________________________________________________
GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at http://www.inbox.com/smileys
Works with AIM®, MSN® Messenger, Yahoo!® Messenger, ICQ®, Google Talk™ and
most webmails

Re: [flask] Is there a way of serving HTTPS in Flask? -- SOLUTION

From:
Mark Grey
Date:
2013-04-27 @ 17:03
Looks good, nice work.


On Sat, Apr 27, 2013 at 1:01 PM, 0byte <pillone@inbox.com> wrote:

> For the record:
>
> How to serve HTTPS *directly* from Flask (great for debugging), no nginx,
> no apache, no gunicorn. Just plain Flask:
> create a SSL context (http://werkzeug.pocoo.org/docs/serving/)
>
> from OpenSSL import SSL
> context = SSL.Context(SSL.SSLv23_METHOD)
> context.use_privatekey_file('yourserver.key')
> context.use_certificate_file('yourserver.crt')
>
> then
>
> app.run(host='127.0.0.1',port='12344', debug = False/True,
> ssl_context=context)
>
> There is a confirmed bug in pyOpenSSL that generates a runtime error:
> https://bugs.launchpad.net/pyopenssl/+bug/900792
>
> The workaround is to put these 2 lines in werkzeug/serving.py
> in class BaseWSGIServer(HTTPServer, object):
> ...
>  def shutdown_request(self,request):
>         request.shutdown()
>
> enjoy,
> 0
>
> ____________________________________________________________
> GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at
> http://www.inbox.com/smileys
> Works with AIM®, MSN® Messenger, Yahoo!® Messenger, ICQ®, Google Talk™ and
> most webmails
>
>
>