Issues with Heroku sample example application for Python running locally with SSL

I started with the same problem as in this question . As one of the answers suggests, this particular problem can be avoided by making the application work without SSL. But since Facebook is set up to implement https for apps in just a few days (October 1, 2011), this seems like a solution that will not continue. First I tried to enable ssl in app.run (near line 149 in exampleapp.py . For example:

 app.run(host='0.0.0.0', port=port, ssl_context='adhoc') 

First, try so that he does not start complaining about the missing OpenSSL module. I found a couple of suggestions on how to fix this on the network, and select:

 (myapp)$ pip install pyopenssl 

Now no complaints at startup:

 (myapp)$ foreman start 10:35:25 web.1 | started with pid 26934 10:35:26 web.1 | * Running on https://0.0.0.0:5000/ 10:35:26 web.1 | * Restarting with reloader 

But when trying to access the application:

 10:35:31 web.1 | ---------------------------------------- 10:35:31 web.1 | Exception happened during processing of request from ('127.0.0.1', 61118) 10:35:31 web.1 | Traceback (most recent call last): 10:35:31 web.1 | File "/usr/local/Cellar/python/2.7.1/lib/python2.7/SocketServer.py", line 284, in _handle_request_noblock 10:35:31 web.1 | self.process_request(request, client_address) 10:35:31 web.1 | File "/usr/local/Cellar/python/2.7.1/lib/python2.7/SocketServer.py", line 310, in process_request 10:35:31 web.1 | self.finish_request(request, client_address) 10:35:31 web.1 | File "/usr/local/Cellar/python/2.7.1/lib/python2.7/SocketServer.py", line 323, in finish_request 10:35:31 web.1 | self.RequestHandlerClass(request, client_address, self) 10:35:31 web.1 | File "/usr/local/Cellar/python/2.7.1/lib/python2.7/SocketServer.py", line 639, in __init__ 10:35:31 web.1 | self.handle() 10:35:31 web.1 | File "path_to_myapp/lib/python2.7/site-packages/werkzeug/serving.py", line 189, in handle 10:35:31 web.1 | return rv 10:35:31 web.1 | UnboundLocalError: local variable 'rv' referenced before assignment 10:35:31 web.1 | ---------------------------------------- 10:35:31 web.1 | Unhandled exception in thread started by <function inner at 0x10139e050> 10:35:31 web.1 | Traceback (most recent call last): 10:35:31 web.1 | File "path_to_myapp/lib/python2.7/site-packages/werkzeug/serving.py", line 599, in inner 10:35:31 web.1 | passthrough_errors, ssl_context).serve_forever() 10:35:31 web.1 | File "path_to_myapp/lib/python2.7/site-packages/werkzeug/serving.py", line 355, in serve_forever 10:35:31 web.1 | HTTPServer.serve_forever(self) 10:35:31 web.1 | File "/usr/local/Cellar/python/2.7.1/lib/python2.7/SocketServer.py", line 227, in serve_forever 10:35:31 web.1 | self._handle_request_noblock() 10:35:31 web.1 | File "/usr/local/Cellar/python/2.7.1/lib/python2.7/SocketServer.py", line 287, in _handle_request_noblock 10:35:31 web.1 | self.shutdown_request(request) 10:35:31 web.1 | File "/usr/local/Cellar/python/2.7.1/lib/python2.7/SocketServer.py", line 459, in shutdown_request 10:35:31 web.1 | request.shutdown(socket.SHUT_WR) 10:35:31 web.1 | TypeError: shutdown() takes exactly 0 arguments (1 given) 

What to do? Is this the wrong version of Python, or was it just that I missed some other fundamental thing?

+6
source share
2 answers

This is a bug in Werkzeug that got fixed .

Change the version of Werkzeug in the requirements.txt file to at least 0.8.2 and run pip install -r requirements.txt to update.

+1
source

It is difficult to find out why rv fails without checking the local environment, scripts, installed modules, and werkzeug code, which claims that SSL is supported from v0.6 onwards.

The easiest solution is to install the grandfather of apache web servers on your local computer, add mod_ssl and generate these SSL certificates. Finally, add mod_wsgi as described in the Flask man page to launch your application.

Note: the installation can be difficult for the first timers, but once you get started, apache is a workhorse and has been extremely reliable for me over the past 15 years.

+1
source

Source: https://habr.com/ru/post/898192/


All Articles