I am having problems running Django(1.8.7) app on scalable OpenShift platform using python 2.7. For some reason it can not get info of enviroment variable OPENSHIFT_POSTGRESQL_DB_URL
. Well this is the error:
mod_wsgi (pid=69306): Target WSGI script '/var/lib/openshift/5d5/app-root/runtime/repo/wsgi/application' cannot be loaded as Python module.
mod_wsgi (pid=69306): Exception occurred processing WSGI script '/var/lib/openshift/5d5/app-root/runtime/repo/wsgi/application'.
Traceback (most recent call last):
File "/var/lib/openshift/5d5/app-root/runtime/repo/wsgi/application", line 21, in <module>
application = get_wsgi_application()
File "/var/lib/openshift/5d5/python/virtenv/lib/python2.7/site-packages/Django-1.8.7-py2.7.egg/django/core/wsgi.py", line 14, in get_wsgi_application
django.setup()
File "/var/lib/openshift/5d5/python/virtenv/lib/python2.7/site-packages/Django-1.8.7-py2.7.egg/django/__init__.py", line 17, in setup
configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
File "/var/lib/openshift/5d5/python/virtenv/lib/python2.7/site-packages/Django-1.8.7-py2.7.egg/django/conf/__init__.py", line 48, in __getattr__
self._setup(name)
File "/var/lib/openshift/5d5/python/virtenv/lib/python2.7/site-packages/Django-1.8.7-py2.7.egg/django/conf/__init__.py", line 44, in _setup
self._wrapped = Settings(settings_module)
File "/var/lib/openshift/5d5/python/virtenv/lib/python2.7/site-packages/Django-1.8.7-py2.7.egg/django/conf/__init__.py", line 92, in __init__
mod = importlib.import_module(self.SETTINGS_MODULE)
File "/opt/rh/python27/root/usr/lib64/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/var/lib/openshift/5d5/app-root/runtime/repo/wsgi/bet/controller/settings.py", line 59, in <module>
url = urlparse.urlparse(os.environ.get('OPENSHIFT_POSTGRESQL_DB_URL'))
File "/opt/rh/python27/root/usr/lib64/python2.7/urlparse.py", line 143, in urlparse
tuple = urlsplit(url, scheme, allow_fragments)
File "/opt/rh/python27/root/usr/lib64/python2.7/urlparse.py", line 182, in urlsplit
i = url.find(':')
AttributeError: 'NoneType' object has no attribute 'find'
This is how I used that variable in settings.py that worked before:
import urlparse
DATABASES = {}
if ON_OPENSHIFT:
url = urlparse.urlparse(os.environ.get('OPENSHIFT_POSTGRESQL_DB_URL'))
DATABASES['default'] = {
'ENGINE' : 'django.db.backends.postgresql_psycopg2',
'NAME': os.environ['OPENSHIFT_APP_NAME'],
'USER': url.username,
'PASSWORD': url.password,
'HOST': url.hostname,
'PORT': url.port,
}
and this is my application
file:
#!/usr/bin/env python
import os
import sys
sys.path.append(os.path.join(os.environ['OPENSHIFT_REPO_DIR'], 'wsgi', 'bet'))
os.environ['DJANGO_SETTINGS_MODULE'] = 'controller.settings'
virtenv = os.environ['OPENSHIFT_PYTHON_DIR'] + '/virtenv/'
virtualenv = os.path.join(virtenv, 'bin/activate_this.py')
try:
execfile(virtualenv, dict(__file__=virtualenv))
except:
pass
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
If I login to my app through rhc ssh bet
and try to print variable, it works ok:
echo $OPENSHIFT_POSTGRESQL_DB_URL
postgresql://admin:password-mynick.rhcloud.com:port/
And idea what am I missing. I look here with no luck.
NOTE: My app is named bet
. But since I am moving it to scalable app, I created abet
app in openshift. I kept name of app as bet
in wsgi
folder. Might this cause some problems?