librelist archives

« back to archive

Problem with Flask and Serving HTTPS --

Problem with Flask and Serving HTTPS --

From:
Marg Lyell
Date:
2014-05-23 @ 16:43
Hi All,

I am new to the mailing list and pretty new to Python.  Sorry for the long
post, but I can't find what I am missing on this.


I am working on using Flask to serve HTTPS pages, the host is a raspberry 
pi.  I am using a Firefox (v 28) browser to connect to the flask-served 
web page. The Python version is 2.7.3  My browser is on a different 
machine (not on the pi).


First, when I use Flask to serve the HTTP pages from the RPi, it works great.

When I started working to incorporate HTTPS / SSL, I generated the known 
error (but new to me)   of 

     TypeEffort: shutdown() takes exactly 0 arguments (1 given) that is 
generated from Python's  SocketServer.py  that tracks back to 
werkzeug.serving.py

I found the fix at  http://flask.pocoo.org/snippets/111/ -- but have not 
been able to get it to work.

When I try the fix in my code, and point my browser to the website I 
simply get the error that the server is down or busy, try later. Nothing 
else obvious.  [I am connecting to the pi over ssh from my usual 
platform.]


I delved into Python and learned about adding a new function to a class:

My relevant code is:
    from flask import Flask, render_template (.... other methods)
    from Werkzeug.serving import BasicWSGIServer
    

   def shutdown_request(self,request):
          request.shutdown()
   setattr(BasicWSGIServer, 'shutdown_request', shutdown_request)
  

   from OpenSSL import SSL


I noticed that others have been able to get this to work.

Any ideas would be welcome.

Thanks,
Margaret 










 
 How to serve HTTPS *directly* from Flask (no nginx, no apache, no 
gunicorn) | Flask (A Pytho...
Flask Snippets overview // docs // community // snippets // extensions // 
search How to serve HTTPS *directly* from Flask (no nginx, no apache, no 
gunicorn)   
View on flask.pocoo.org Preview by Yahoo  

Re: [flask] Problem with Flask and Serving HTTPS --

From:
gioi
Date:
2014-05-23 @ 16:55
I guess you aren't debugging - and so you should use a fully-featured 
webserver. Maybe gunicorn or nginx will do.

BTW, can you please post the full traceback?

Re: [flask] Problem with Flask and Serving HTTPS --

From:
James 'Iv0ryW0lf' Boyd
Date:
2014-05-23 @ 17:01
I currently have this working on my system.  Did you generate your certificates?  

Marg Lyell <mltech2011@yahoo.com> wrote:

>Hi All,
>
>
>I am new to the mailing list and pretty new to Python.  Sorry for the 
long post, but I can't find what I am missing on this.
>
>
>I am working on using Flask to serve HTTPS pages, the host is a raspberry
pi.  I am using a Firefox (v 28) browser to connect to the flask-served 
web page. The Python version is 2.7.3  My browser is on a different 
machine (not on the pi).
>
>
>First, when I use Flask to serve the HTTP pages from the RPi, it works great.
>
>
>When I started working to incorporate HTTPS / SSL, I generated the known 
error (but new to me)   of 
>
>     TypeEffort: shutdown() takes exactly 0 arguments (1 given) that is 
generated from Python's  SocketServer.py  that tracks back to 
werkzeug.serving.py
>
>
>I found the fix at  http://flask.pocoo.org/snippets/111/ -- but have not 
been able to get it to work.
>
>
>When I try the fix in my code, and point my browser to the website I 
simply get the error that the server is down or busy, try later. Nothing 
else obvious.  [I am connecting to the pi over ssh from my usual 
platform.]
>
>
>I delved into Python and learned about adding a new function to a class:
>
>
>My relevant code is:
>
>    from flask import Flask, render_template (.... other methods)
>
>    from Werkzeug.serving import BasicWSGIServer
>
>    
>
>   def shutdown_request(self,request):
>
>          request.shutdown()
>
>   setattr(BasicWSGIServer, 'shutdown_request', shutdown_request)
>

>
>   from OpenSSL import SSL
>
>
>
>I noticed that others have been able to get this to work.
>
>
>Any ideas would be welcome.
>
>
>Thanks,
>
>Margaret 
>
>
>
>
>
>
>
>
>
>
>How to serve HTTPS *directly* from Flask (no nginx, no apache, no 
gunicorn) | Flask (A Pytho...
>
>Flask Snippets overview // docs // community // snippets // extensions //
search How to serve HTTPS *directly* from Flask (no nginx, no apache, no 
gunicorn) 
>
>View on flask.pocoo.org
>
>Preview by Yahoo
>
>
>
>
>
>

Re: [flask] Problem with Flask and Serving HTTPS --

From:
Marg Lyell
Date:
2014-05-23 @ 17:16
I did generate certificates --  used openSSL commands at the command line.  

This is a possible spot to look at details -- I'm going to take a look at 
whether the params I gave are ok with python openssl.

Thanks,
Margaret 




On Friday, May 23, 2014 1:04 PM, James 'Iv0ryW0lf' Boyd 
<james@ivorywolf.com> wrote:
 


I currently have this working on my system.  Did you generate your certificates? 

Marg Lyell <mltech2011@yahoo.com> wrote:


Hi All,

I am new to the mailing list and pretty new to Python.  Sorry for the long
post, but I can't find what I am missing on this.


I am working on using Flask to serve HTTPS pages, the host is a raspberry 
pi.  I am using a Firefox (v 28) browser to connect to the flask-served 
web page. The Python version is 2.7.3  My browser is on a different 
machine (not on the pi).


First, when I use Flask to serve the HTTP pages from the RPi, it works great.

When I started working to incorporate HTTPS / SSL, I generated the known 
error (but new to me)   of 

     TypeEffort: shutdown() takes exactly 0 arguments (1 given) that is 
generated from Python's  SocketServer.py  that tracks back to 
werkzeug.serving.py

I found the fix at  http://flask.pocoo.org/snippets/111/ -- but have not 
been able to get it to work.

When I try the fix in my code, and point my browser to the website I 
simply get the error that the server is down or busy, try later. Nothing 
else obvious.  [I am connecting to the pi over ssh from my usual 
platform.]


I delved into Python and learned about adding a new function to a class:

My relevant code is:
    from flask import Flask, render_template (.... other methods)
    from Werkzeug.serving import BasicWSGIServer
    

   def shutdown_request(self,request):
          request.shutdown()
   setattr(BasicWSGIServer, 'shutdown_request', shutdown_request)
  

   from OpenSSL import SSL


I noticed that others have been able to get this to work.

Any ideas would be welcome.

Thanks,
Margaret 










 
 How to serve HTTPS *directly* from Flask (no nginx, no apache, no 
gunicorn) | Flask (A Pytho...
Flask Snippets overview // docs // community // snippets // extensions // 
search How to serve HTTPS *directly* from Flask (no nginx, no apache, no 
gunicorn)   
View on flask.pocoo.org Preview by Yahoo  

Re: [flask] Problem with Flask and Serving HTTPS --

From:
Iv0ryW0lf
Date:
2014-05-23 @ 22:53
Based on these code snippets, mine works.

#/usr/bin/env python
from flask import Flask, url_for, render_template, request
from OpenSSL import SSL

context = SSL.Context(SSL.SSLv23_METHOD)
context.use_privatekey_file('certs/server.key')  #Location of Key
context.use_certificate_file('certs/server.crt') #Location of Cert

...

if __name__ == "__main__":
     app.run(host='0.0.0.0', port=8443, ssl_context=context)


This is the method I used to create the key and cert.

openssl genrsa -des3 -passout pass:x -out server.pass.key 2048
openssl rsa -passin pass:x -in server.pass.key -out server.key
openssl req -new -key server.key -out server.csr
openssl x509 -req -days 365 -in server.csr -signkey server.key -out 
server.crt
cp server.crt server.key certs/

-- J

On 5/23/2014 12:16 PM, Marg Lyell wrote:
> I did generate certificates -- used openSSL commands at the command line.
>
> This is a possible spot to look at details -- I'm going to take a look 
> at whether the params I gave are ok with python openssl.
>
> Thanks,
> Margaret
>
>
>
> On Friday, May 23, 2014 1:04 PM, James 'Iv0ryW0lf' Boyd 
> <james@ivorywolf.com> wrote:
>
>
> I currently have this working on my system. Did you generate your 
> certificates?
>
> Marg Lyell <mltech2011@yahoo.com> wrote:
>
> Hi All,
>
> I am new to the mailing list and pretty new to Python.  Sorry for the 
> long post, but I can't find what I am missing on this.
>
> I am working on using Flask to serve HTTPS pages, the host is a 
> raspberry pi.  I am using a Firefox (v 28) browser to connect to the 
> flask-served web page. The Python version is 2.7.3  My browser is on a 
> different machine (not on the pi).
>
> First, when I use Flask to serve the HTTP pages from the RPi, it works 
> great.
>
> When I started working to incorporate HTTPS / SSL, I generated the 
> known error (but new to me)   of
> TypeEffort: shutdown() takes exactly 0 arguments (1 given) that is 
> generated from Python's SocketServer.py  that tracks back to 
> werkzeug.serving.py
>
> I found the fix at http://flask.pocoo.org/snippets/111/ -- but have 
> not been able to get it to work.
>
> When I try the fix in my code, and point my browser to the website I 
> simply get the error that the server is down or busy, try later. 
> Nothing else obvious. [I am connecting to the pi over ssh from my 
> usual platform.]
>
> I delved into Python and learned about adding a new function to a class:
>
> My relevant code is:
> from flask import Flask, render_template (.... other methods)
> from Werkzeug.serving import BasicWSGIServer
>
> def shutdown_request(self,request):
> request.shutdown()
> setattr(BasicWSGIServer, 'shutdown_request', shutdown_request)
>
> from OpenSSL import SSL
>
>
> I noticed that others have been able to get this to work.
>
> Any ideas would be welcome.
>
> Thanks,
> Margaret
>
>
>
>
>
>
>
>
>
>
>
> 	
> How to serve HTTPS *directly* from Flask (no nginx, no apache, no 
> gunicorn) | Flask (A Pytho... <http://flask.pocoo.org/snippets/111/>
> Flask Snippets overview // docs // community // snippets // extensions 
> // search How to serve HTTPS *directly* from Flask (no nginx, no 
> apache, no gunicorn)
> 	
> View on flask.pocoo.org <http://flask.pocoo.org/snippets/111/>
> 	
> Preview by Yahoo
>
>
>
>
>
>
>
>

Re: [flask] Problem with Flask and Serving HTTPS --

From:
Iv0ryW0lf
Date:
2014-05-23 @ 22:58
I tested the connection by using: wget --user-agent="Test Message" 
--no-check-certificate https://127.0.0.1:8443/

The page returned the user-agent string.


On 5/23/2014 5:53 PM, Iv0ryW0lf wrote:
> Based on these code snippets, mine works.
>
> #/usr/bin/env python
> from flask import Flask, url_for, render_template, request
> from OpenSSL import SSL
>
> context = SSL.Context(SSL.SSLv23_METHOD)
> context.use_privatekey_file('certs/server.key')  #Location of Key
> context.use_certificate_file('certs/server.crt') #Location of Cert
>
> ...
>
> if __name__ == "__main__":
>     app.run(host='0.0.0.0', port=8443, ssl_context=context)
>
>
> This is the method I used to create the key and cert.
>
> openssl genrsa -des3 -passout pass:x -out server.pass.key 2048
> openssl rsa -passin pass:x -in server.pass.key -out server.key
> openssl req -new -key server.key -out server.csr
> openssl x509 -req -days 365 -in server.csr -signkey server.key -out 
> server.crt
> cp server.crt server.key certs/
>
> -- J
>
> On 5/23/2014 12:16 PM, Marg Lyell wrote:
>> I did generate certificates -- used openSSL commands at the command 
>> line.
>>
>> This is a possible spot to look at details -- I'm going to take a 
>> look at whether the params I gave are ok with python openssl.
>>
>> Thanks,
>> Margaret
>>
>>
>>
>> On Friday, May 23, 2014 1:04 PM, James 'Iv0ryW0lf' Boyd 
>> <james@ivorywolf.com> wrote:
>>
>>
>> I currently have this working on my system. Did you generate your 
>> certificates?
>>
>> Marg Lyell <mltech2011@yahoo.com> wrote:
>>
>> Hi All,
>>
>> I am new to the mailing list and pretty new to Python. Sorry for the 
>> long post, but I can't find what I am missing on this.
>>
>> I am working on using Flask to serve HTTPS pages, the host is a 
>> raspberry pi.  I am using a Firefox (v 28) browser to connect to the 
>> flask-served web page. The Python version is 2.7.3  My browser is on 
>> a different machine (not on the pi).
>>
>> First, when I use Flask to serve the HTTP pages from the RPi, it 
>> works great.
>>
>> When I started working to incorporate HTTPS / SSL, I generated the 
>> known error (but new to me)   of
>> TypeEffort: shutdown() takes exactly 0 arguments (1 given) that is 
>> generated from Python's SocketServer.py  that tracks back to 
>> werkzeug.serving.py
>>
>> I found the fix at http://flask.pocoo.org/snippets/111/ -- but have 
>> not been able to get it to work.
>>
>> When I try the fix in my code, and point my browser to the website I 
>> simply get the error that the server is down or busy, try later. 
>> Nothing else obvious.  [I am connecting to the pi over ssh from my 
>> usual platform.]
>>
>> I delved into Python and learned about adding a new function to a class:
>>
>> My relevant code is:
>>     from flask import Flask, render_template (.... other methods)
>>     from Werkzeug.serving import BasicWSGIServer
>>
>>    def shutdown_request(self,request):
>> request.shutdown()
>> setattr(BasicWSGIServer, 'shutdown_request', shutdown_request)
>>
>>    from OpenSSL import SSL
>>
>>
>> I noticed that others have been able to get this to work.
>>
>> Any ideas would be welcome.
>>
>> Thanks,
>> Margaret
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> 	
>> How to serve HTTPS *directly* from Flask (no nginx, no apache, no 
>> gunicorn) | Flask (A Pytho... <http://flask.pocoo.org/snippets/111/>
>> Flask Snippets overview // docs // community // snippets // 
>> extensions // search How to serve HTTPS *directly* from Flask (no 
>> nginx, no apache, no gunicorn)
>> 	
>> View on flask.pocoo.org <http://flask.pocoo.org/snippets/111/>
>> 	
>> Preview by Yahoo
>>
>>
>>
>>
>>
>>
>>
>>
>

Re: [flask] Problem with Flask and Serving HTTPS --

From:
Marg Lyell
Date:
2014-05-24 @ 00:46
James,
Much thanks for the all the info.

I did generate the cert and keys using the above command set, even using des3.  

My use of the context is identical to yours (up to the path difference).
And the run command is the same, up to the port and I have set debug to True.


I also tried (today) an alternate where I generated the cert and key from 
python openssl apis programmatically, with the same null result.

It looks like you are testing from the local host. 

My testing has been from another machine on the web, using a Firefox 
browser pointed at IP address with the port #. 

[As part of the testing I just did a change to /etc/hosts  to include the 
IP address of the RPi from which I'm (attempting to be) serving the 
webpage. No change in result]


I can't think of a reason why connectivity from a browser (firefox) that 
is hosted on another machine on the lan would fail. 


I really appreciate the sanity check.

I guess my next step is to start from scratch and work through everything again.

Thanks again,
Margaret 




On Friday, May 23, 2014 7:01 PM, Iv0ryW0lf <iv0ryw0lf@satxhackers.org> wrote:
 


I tested the connection by using: wget --user-agent="Test Message" 
--no-check-certificate https://127.0.0.1:8443/

The page returned the user-agent string.


On 5/23/2014 5:53 PM, Iv0ryW0lf wrote:

Based on these code snippets, mine works.

#/usr/bin/env python
from flask import Flask, url_for, render_template, request
from OpenSSL import SSL

context = SSL.Context(SSL.SSLv23_METHOD)
context.use_privatekey_file('certs/server.key')  #Location of
        Key
context.use_certificate_file('certs/server.crt') #Location of
        Cert

...

if __name__ == "__main__":
    app.run(host='0.0.0.0', port=8443, ssl_context=context)


This is the method I used to create the key and cert.

openssl genrsa -des3 -passout pass:x -out server.pass.key 2048
openssl rsa -passin pass:x -in server.pass.key -out server.key
openssl req -new -key server.key -out server.csr
openssl x509 -req -days 365 -in server.csr -signkey server.key
        -out server.crt
cp server.crt server.key certs/
 
-- J

On 5/23/2014 12:16 PM, Marg Lyell wrote:

I did generate certificates --  used openSSL commands at the command line.  
>
>
>This is a possible spot to look at details -- I'm going to take a look at
whether the params I gave are ok with python openssl.
>
>
>Thanks,
>Margaret 
>
>
>
>
>
>On Friday, May 23, 2014 1:04 PM, James 'Iv0ryW0lf' Boyd 
<james@ivorywolf.com> wrote:
> 
>
>
>I currently have this working on my system. Did you generate your certificates? 
>
>Marg Lyell <mltech2011@yahoo.com> wrote:
>
>
>Hi All,
>
>
>I am new to the mailing list and pretty new to Python.  Sorry for the 
long post, but I can't find what I am missing on this.
>
>
>
>I am working on using Flask to serve HTTPS pages, the host is a raspberry
pi.  I am using a Firefox (v 28) browser to connect to the flask-served 
web page. The Python version is 2.7.3  My browser is on a different 
machine (not on the pi).
>
>
>
>First, when I use Flask to serve the HTTP pages from the RPi, it works great.
>
>
>When I started working to incorporate HTTPS / SSL, I generated the known 
error (but new to me)   of 
>
>     TypeEffort: shutdown() takes exactly 0 arguments (1 given) that is 
generated from Python's  SocketServer.py  that tracks back to 
werkzeug.serving.py
>
>
>I found the fix at  http://flask.pocoo.org/snippets/111/ -- but have not 
been able to get it to work.
>
>
>When I try the fix in my code, and point my browser to the website I 
simply get the error that the server is down or busy, try later. Nothing 
else obvious.  [I am connecting to the pi over ssh from my usual 
platform.]
>
>
>
>I delved into Python and learned about adding a new function to a class:
>
>
>My relevant code is:
>    from flask import Flask, render_template (.... other methods)
>    from Werkzeug.serving import BasicWSGIServer
>    
>
>   def shutdown_request(self,request):
>          request.shutdown()
>   setattr(BasicWSGIServer, 'shutdown_request', shutdown_request)

>
>   from OpenSSL import SSL
>
>
>
>
>I noticed that others have been able to get this to work.
>
>
>Any ideas would be welcome.
>
>
>Thanks,
>Margaret 
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> 
>
> How to serve HTTPS *directly* from Flask (no nginx, no apache, no 
gunicorn) | Flask (A Pytho... 
>Flask Snippets overview // docs // community // snippets // extensions //
search How to serve HTTPS *directly* from Flask (no nginx, no apache, no 
gunicorn)  
> 
>View on flask.pocoo.org Preview by Yahoo 
>
> 
>
>
>
>
>
>
>
>
>
>
>
>