Reputation: 360
I've been struggling to deploy a Flask application in Openshift. First of all, I tried to deploy an application I am developing. As I didn't succeed, I decided to create a sample Hello World and deploy it.
Here is the code of app.py
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def hello_world():
return render_template('index.html')
if __name__ == '__main__':
app.run()
I do use the install_requirements in setup.py file:
from setuptools import setup
setup(name='SweetyPro',
version='1.0',
description='OpenShift App',
author='Your Name',
author_email='[email protected]',
url='http://www.python.org/sigs/distutils-sig/',
install_requires=['Django>=1.3',
'Flask==0.11.1'], )
I also set up flask and a requirement in requirements.txt. However, Openshift only says it is a Service Temporarily Unavailable.
I checked out the log through rhc tail -a my_application, and it prompts me this:
==> app-root/logs/python.log <==
Traceback (most recent call last):
File "app.py", line 10, in <module>
app.run()
File "/var/lib/openshift/57976d4c7628e1a34e000179/python/virtenv/lib/python2.7/site-packages/Flask-0.11.1-py2.7.egg/flask/app.py", line 843, in run
run_simple(host, port, self, **options)
File "/var/lib/openshift/57976d4c7628e1a34e000179/python/virtenv/lib/python2.7/site-packages/Werkzeug-0.11.10-py2.7.egg/werkzeug/serving.py", line 694, in run_simple
inner()
File "/var/lib/openshift/57976d4c7628e1a34e000179/python/virtenv/lib/python2.7/site-packages/Werkzeug-0.11.10-py2.7.egg/werkzeug/serving.py", line 656, in inner
fd=fd)
File "/var/lib/openshift/57976d4c7628e1a34e000179/python/virtenv/lib/python2.7/site-packages/Werkzeug-0.11.10-py2.7.egg/werkzeug/serving.py", line 550, in make_server
passthrough_errors, ssl_context, fd=fd)
File "/var/lib/openshift/57976d4c7628e1a34e000179/python/virtenv/lib/python2.7/site-packages/Werkzeug-0.11.10-py2.7.egg/werkzeug/serving.py", line 464, in __init__
HTTPServer.__init__(self, (host, int(port)), handler)
File "/opt/rh/python27/root/usr/lib64/python2.7/SocketServer.py", line 419, in __init__
self.server_bind()
File "/opt/rh/python27/root/usr/lib64/python2.7/BaseHTTPServer.py", line 108, in server_bind
SocketServer.TCPServer.server_bind(self)
File "/opt/rh/python27/root/usr/lib64/python2.7/SocketServer.py", line 430, in server_bind
self.socket.bind(self.server_address)
File "/opt/rh/python27/root/usr/lib64/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 13] Permission denied
Could anyone help me out, please? I already did what I could. Thank you!
Upvotes: 1
Views: 3671
Reputation: 58563
Because you have supplied an app.py
file, it will be run to start your application. This will use the builtin Flask development server with the way the code is setup. In doing that though, you need to tell the Flask development server which port to listen on, you can't use the default port that the Flask development server users. The port is available in the OPENSHIFT_PYTHON_PORT
environment variable. See:
You may also need to use OPENSHIFT_PYTHON_IP
environment variable and tell the Flask development server what host interface to bind to if by default it only listens on localhost.
An alternative to all that is to rename your app.py
file to wsgi.py
and add:
application = app
after the Flask application object is created. By making that change then OpenShift will host the application with Apache/mod_wsgi instead and it will worry about how to host it.
Upvotes: 2