A Django service giving Internal server error - python

I am running a web application developed in Django. When the appication is run, it is giving internal server error.
Here is the apache log
[Fri May 27 23:15:32 2016] [error] [client 203.110.245.243] mod_wsgi (pid=554): Target WSGI script '/home/randUser/DisCern/DisCern/wsgi.py' cannot be loaded as Python module.
[Fri May 27 23:15:32 2016] [error] [client 203.110.245.243] mod_wsgi (pid=554): Exception occurred processing WSGI script '/home/randUser/DisCern/DisCern/wsgi.py'.
[Fri May 27 23:15:32 2016] [error] [client 203.110.245.243] Traceback (most recent call last):
[Fri May 27 23:15:32 2016] [error] [client 203.110.245.243] File "/home/ankesh/DisCern/DisCern/wsgi.py", line 25, in <module>
[Fri May 27 23:15:32 2016] [error] [client 203.110.245.243] application = get_wsgi_application()
[Fri May 27 23:15:32 2016] [error] [client 203.110.245.243] File "/home/ankesh/DisCern/env/lib/python2.7/site-packages/django/core/wsgi.py", line 14, in get_wsgi_application
[Fri May 27 23:15:32 2016] [error] [client 203.110.245.243] django.setup()
[Fri May 27 23:15:32 2016] [error] [client 203.110.245.243] File "/home/ankesh/DisCern/env/lib/python2.7/site-packages/django/__init__.py", line 20, in setup
[Fri May 27 23:15:32 2016] [error] [client 203.110.245.243] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[Fri May 27 23:15:32 2016] [error] [client 203.110.245.243] File "/home/ankesh/DisCern/env/lib/python2.7/site-packages/django/conf/__init__.py", line 46, in __getattr__
[Fri May 27 23:15:32 2016] [error] [client 203.110.245.243] self._setup(name)
[Fri May 27 23:15:32 2016] [error] [client 203.110.245.243] File "/home/ankesh/DisCern/env/lib/python2.7/site-packages/django/conf/__init__.py", line 42, in _setup
[Fri May 27 23:15:32 2016] [error] [client 203.110.245.243] self._wrapped = Settings(settings_module)
[Fri May 27 23:15:32 2016] [error] [client 203.110.245.243] File "/home/ankesh/DisCern/env/lib/python2.7/site-packages/django/conf/__init__.py", line 98, in __init__
[Fri May 27 23:15:32 2016] [error] [client 203.110.245.243] % (self.SETTINGS_MODULE, e)
[Fri May 27 23:15:32 2016] [error] [client 203.110.245.243] ImportError: Could not import settings 'DisCern.settings' (Is it on sys.path? Is there an import error in the settings file?): No module named DisCern.settings
Here is the wsgi.py file
import os
import sys
import site
# Add the site-packages of the chosen virtualenv to work with
site.addsitedir('~/DisCern/env/lib/python2.7/site-packages')
# Add the app's directory to the PYTHONPATH
sys.path.append('/home/ankesh/DisCern/DisCern')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "DisCern.settings")
# Activate your virtual env
activate_env=os.path.expanduser("/home/ankesh/DisCern/env/bin/activate_this.py")
execfile(activate_env, dict(__file__=activate_env))
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
What can be the possible error?

Related

How to set environ variables in local development with virtualenv

I am currently trying to publish via ZIP my django app to an AWS elasticbeanstalk.
As I have a local and online development enviroment I would like to make use of the environ variables, that are used anyways by AWS.
For my development environments I am already using virtualenv. Apache runs with wsgi enabled and is supposed to use such environments. Unfortunately, it does not know the environ that I have set in the bin/activate.
Django throws a 500 error, since it cannot connect to the database as it does not have access to the environ vars:
1:53.862779 2015] [wsgi:error] [pid 20639] [remote 127.0.0.1:51896] KeyError: 'RDS_DB_NAME'
If I activate my env and look into the env vars:
(myenv)[bs#debian-gohan:]/var/www/vhosts/mysite $ env | grep RDS
RDS_HOSTNAME=localhost
... and I get the others as well...
My Apache Vhost is:
<VirtualHost *:80>
WSGIDaemonProcess mysite python-path=/home/bs/envs/myenv/bin/python2.7:/home/bs/envs/myenv/lib/python2.7/site-packages
WSGIProcessGroup mysite
WSGIScriptAlias / /var/www/vhosts/main-page/mysite/wsgi.py
Does anyone have an idea why the environ vars are not seen by the apache ?
EDIT 1:
I have tried to use SetEnv in the Apache config, like this:
SetEnv RDS_HOSTNAME "localhost"
Unfortunately, this did not work. I then removed the ProcessGroup and only used a simple WSGIPythonPath. That did not work either.
The error in the apache log remains the same:
[Thu Mar 26 11:30:34.046807 2015] [wsgi:info] [pid 23012] [client 127.0.0.1:55231] mod_wsgi (pid=23012, process='', application='mysite.dbz.dev|'): Loading WSGI script '/var/www/vhosts/main-page/mysite/wsgi.py'.
[Thu Mar 26 11:30:34.178717 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] mod_wsgi (pid=23012): Target WSGI script '/var/www/vhosts/main-page/mysite/wsgi.py' cannot be loaded as Python module.
[Thu Mar 26 11:30:34.178812 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] mod_wsgi (pid=23012): Exception occurred processing WSGI script '/var/www/vhosts/main-page/mysite/wsgi.py'.
[Thu Mar 26 11:30:34.178924 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] Traceback (most recent call last):
[Thu Mar 26 11:30:34.178947 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] File "/var/www/vhosts/main-page/mysite/wsgi.py", line 17, in <module>
[Thu Mar 26 11:30:34.179111 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] application = get_wsgi_application()
[Thu Mar 26 11:30:34.179157 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] File "/usr/local/lib/python2.7/dist-packages/django/core/wsgi.py", line 14, in get_wsgi_application
[Thu Mar 26 11:30:34.179319 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] django.setup()
[Thu Mar 26 11:30:34.179363 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] File "/usr/local/lib/python2.7/dist-packages/django/__init__.py", line 20, in setup
[Thu Mar 26 11:30:34.179606 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
[Thu Mar 26 11:30:34.179651 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 46, in __getattr__
[Thu Mar 26 11:30:34.179774 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] self._setup(name)
[Thu Mar 26 11:30:34.179789 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 42, in _setup
[Thu Mar 26 11:30:34.179918 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] self._wrapped = Settings(settings_module)
[Thu Mar 26 11:30:34.179959 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 94, in __init__
[Thu Mar 26 11:30:34.180072 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] mod = importlib.import_module(self.SETTINGS_MODULE)
[Thu Mar 26 11:30:34.180112 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
[Thu Mar 26 11:30:34.180220 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] __import__(name)
[Thu Mar 26 11:30:34.180246 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] File "/var/www/vhosts/main-page/mysite/../mysite/settings.py", line 94, in <module>
[Thu Mar 26 11:30:34.180400 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] 'NAME': os.environ['RDS_DB_NAME'],
[Thu Mar 26 11:30:34.180443 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] File "/usr/lib/python2.7/UserDict.py", line 23, in __getitem__
[Thu Mar 26 11:30:34.180613 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] raise KeyError(key)
[Thu Mar 26 11:30:34.180665 2015] [wsgi:error] [pid 23012] [client 127.0.0.1:55231] KeyError: 'RDS_DB_NAME'
Set like this
<VirtualHost hostname:80>
...
SetEnv VARIABLE_NAME variable_value
...
</VirtualHost>
In wsgi script.
os.environ.setdefault("variable", "value")
To override variable,
os.environ['var']="val"

Current version of celery and django-celery don't seem compatible

So I currently have installed Celery 3.1.8 (Cipater) and Djcelery 3.1.1 but following the tutorial causes my site to crash
So this tutorial
http://docs.celeryproject.org/en/master/django/first-steps-with-django.html#django-first-steps
I pretty much follow but when I try importing django-celery with this line in settings.py
import djcelery
I get a server error. Looking at the error log it says
[Fri Jan 24 00:47:40 2014] [error] [client 24.61.15.120] mod_wsgi (pid=32567): Exception occurred processing WSGI script '/srv/www/site/app1/wsgi_app1.py'.
[Fri Jan 24 00:47:40 2014] [error] [client 24.61.15.120] Traceback (most recent call last):
[Fri Jan 24 00:47:40 2014] [error] [client 24.61.15.120] File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi_app1.py", line 236, in __call__
[Fri Jan 24 00:47:40 2014] [error] [client 24.61.15.120] self.load_middleware()
[Fri Jan 24 00:47:40 2014] [error] [client 24.61.15.120] File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 45, in load_middleware
[Fri Jan 24 00:47:40 2014] [error] [client 24.61.15.120] for middleware_path in settings.MIDDLEWARE_CLASSES:
[Fri Jan 24 00:47:40 2014] [error] [client 24.61.15.120] File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 52, in __getattr__
[Fri Jan 24 00:47:40 2014] [error] [client 24.61.15.120] self._setup(name)
[Fri Jan 24 00:47:40 2014] [error] [client 24.61.15.120] File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 47, in _setup
[Fri Jan 24 00:47:40 2014] [error] [client 24.61.15.120] self._wrapped = Settings(settings_module)
[Fri Jan 24 00:47:40 2014] [error] [client 24.61.15.120] File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 132, in __init__
[Fri Jan 24 00:47:40 2014] [error] [client 24.61.15.120] raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
[Fri Jan 24 00:47:40 2014] [error] [client 24.61.15.120] ImportError: Could not import settings 'site.settings_app1' (Is it on sys.path?): cannot import name Celery
[Fri Jan 24 00:47:41 2014] [error] [client 24.61.15.120] mod_wsgi (pid=32567): Exception occurred processing WSGI script '/srv/www/site/app1/wsgi_app1.py'.
[Fri Jan 24 00:47:41 2014] [error] [client 24.61.15.120] Traceback (most recent call last):
[Fri Jan 24 00:47:41 2014] [error] [client 24.61.15.120] File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi_app1.py", line 236, in __call__
[Fri Jan 24 00:47:41 2014] [error] [client 24.61.15.120] self.load_middleware()
[Fri Jan 24 00:47:41 2014] [error] [client 24.61.15.120] File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 45, in load_middleware
[Fri Jan 24 00:47:41 2014] [error] [client 24.61.15.120] for middleware_path in settings.MIDDLEWARE_CLASSES:
[Fri Jan 24 00:47:41 2014] [error] [client 24.61.15.120] File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 52, in __getattr__
[Fri Jan 24 00:47:41 2014] [error] [client 24.61.15.120] self._setup(name)
[Fri Jan 24 00:47:41 2014] [error] [client 24.61.15.120] File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 47, in _setup
[Fri Jan 24 00:47:41 2014] [error] [client 24.61.15.120] self._wrapped = Settings(settings_module)
[Fri Jan 24 00:47:41 2014] [error] [client 24.61.15.120] File "/usr/local/lib/python2.7/dist-packages/django/conf/__init__.py", line 132, in __init__
[Fri Jan 24 00:47:41 2014] [error] [client 24.61.15.120] raise ImportError("Could not import settings '%s' (Is it on sys.path?): %s" % (self.SETTINGS_MODULE, e))
[Fri Jan 24 00:47:41 2014] [error] [client 24.61.15.120] ImportError: Could not import settings 'site.settings_app1' (Is it on sys.path?): cannot import name Celery
I'm not sure how to even move on. That import is literally what's causing the problem and I need to use djcelery to utilize the Django backend stuff
Edit:
I'm aware that you don't need djcelery for most things but in the release notes for 3.1 it says
http://docs.celeryproject.org/en/master/whatsnew-3.1.html#django-supported-out-of-the-box
Some features still require the django-celery library:
Celery does not implement the Django database or cache result backends.
Celery does not ship with the database-based periodic task
scheduler.
And I want to use my DB as the backend
Well, this still is an issue but I learned that you actually don't need django-celery at all to allow DB saves so I'm going to consider this answered

Django Application deployment on linux server

I am trying to deploy django application on Linux server with mod_wsgi.
Below are my setting for apache in httpd.conf file -
<VirtualHost 127.0.0.1:8080>
AddDefaultCharset utf-8
LogLevel warn
ServerName myappletrade.com
#WSGIProcessGroup appletrade
WSGIScriptAlias / /var/www/html/appletrade/django.wsgi
DocumentRoot /var/www/html/appletrade
#WSGIDaemonProcess frontend user=vasim group=www
ServerAlias myappletrade.com
CustomLog /var/www/html/appletrade/access_log combined
ErrorLog /var/www/html/appletrade/error_log
<Directory /var/www/html/appletrade>
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
django.wsgi file settings -
import os
import sys
sys.path.insert(0, "appletrade")
sys.path.insert(0, "/var/www/html/appletrade/noneapp/env/lib/python2.6/site-packages" )
os.environ['DJANGO_SETTINGS_MODULE'] = 'noneapp.settings.development'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
inside noneapp folder I have setting files for development ,production server.
When I am trying to for myappletrade.com in browser nothing happens.it shows 500 internal server error.
I have checked error log . where it's saying -
[Sat Mar 30 18:07:55 2013] [error] [client 127.0.0.1] mod_wsgi (pid=2828): Exception occurred processing WSGI script '/var/www/html/appletrade/django.wsgi'.
[Sat Mar 30 18:07:55 2013] [error] [client 127.0.0.1] Traceback (most recent call last):
[Sat Mar 30 18:07:55 2013] [error] [client 127.0.0.1] File "/usr/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 241, in __call__
[Sat Mar 30 18:07:55 2013] [error] [client 127.0.0.1] response = self.get_response(request)
[Sat Mar 30 18:07:55 2013] [error] [client 127.0.0.1] File "/usr/lib/python2.7/site-packages/django/core/handlers/base.py", line 179, in get_response
[Sat Mar 30 18:07:55 2013] [error] [client 127.0.0.1] response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
[Sat Mar 30 18:07:55 2013] [error] [client 127.0.0.1] File "/usr/lib/python2.7/site-packages/django/core/handlers/base.py", line 224, in handle_uncaught_exception
[Sat Mar 30 18:07:55 2013] [error] [client 127.0.0.1] if resolver.urlconf_module is None:
[Sat Mar 30 18:07:55 2013] [error] [client 127.0.0.1] File "/usr/lib/python2.7/site-packages/django/core/urlresolvers.py", line 323, in urlconf_module
[Sat Mar 30 18:07:55 2013] [error] [client 127.0.0.1] self._urlconf_module = import_module(self.urlconf_name)
[Sat Mar 30 18:07:55 2013] [error] [client 127.0.0.1] File "/usr/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
[Sat Mar 30 18:07:55 2013] [error] [client 127.0.0.1] __import__(name)
[Sat Mar 30 18:07:55 2013] [error] [client 127.0.0.1] File "/var/www/html/appletrade/noneapp/urls/production.py", line 4, in <module>
[Sat Mar 30 18:07:55 2013] [error] [client 127.0.0.1] from noneapp.urls.default import urlpatterns as default_urlpatterns
[Sat Mar 30 18:07:55 2013] [error] [client 127.0.0.1] File "/var/www/html/appletrade/noneapp/urls/default.py", line 6, in <module>
[Sat Mar 30 18:07:55 2013] [error] [client 127.0.0.1] url(r'^catalog/', include('appletrade.urls', namespace = "catalog")),
[Sat Mar 30 18:07:55 2013] [error] [client 127.0.0.1] File "/usr/lib/python2.7/site-packages/django/conf/urls/__init__.py", line 24, in include
[Sat Mar 30 18:07:55 2013] [error] [client 127.0.0.1] urlconf_module = import_module(urlconf_module)
[Sat Mar 30 18:07:55 2013] [error] [client 127.0.0.1] File "/usr/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
[Sat Mar 30 18:07:55 2013] [error] [client 127.0.0.1] __import__(name)
[Sat Mar 30 18:07:55 2013] [error] [client 127.0.0.1] ImportError: No module named urls
Please check my configuration setting and Let me know if I am missing something.
Thanks in Advance
You are trying to force Python 2.7 to use Python 2.6 libraries. Your django.wsgi lists the python2.6 site packages in the path, but the errors all list python2.7.
Are you using a virtualenv environment as well? Make sure you're using the python installed in that virtual environment, and not the system version - you will be missing any pip installed packages you have.
Upon further review - you don't have all of your variables defined for mod_wsgi in your VirtualHost configuration, either.

webpy with mod_wsgi on apache2 - weird pymongo bson error

I'm running webpy with apache2. This is a really weird error that has got me flummoxed. Have never seen such an error before and I'm wondering what might be the cause.
The error is in the bson pymongo module.
[Wed Jan 30 11:40:28 2013] [error] [client 111.93.158.52] mod_wsgi (pid=27117): Target WSGI script '/var/www/webpy-app/borg/src/app.py' cannot be loaded
as Python module.
[Wed Jan 30 11:40:28 2013] [error] [client 111.93.158.52] mod_wsgi (pid=27117): Exception occurred processing WSGI script '/var/www/webpy-app/borg/src/ap
p.py'.
[Wed Jan 30 11:40:28 2013] [error] [client 111.93.158.52] Traceback (most recent call last):
[Wed Jan 30 11:40:28 2013] [error] [client 111.93.158.52] File "/var/www/webpy-app/borg/src/app.py", line 1, in <module>
[Wed Jan 30 11:40:28 2013] [error] [client 111.93.158.52] import web,json,csv,pymongo,pdb,sys
[Wed Jan 30 11:40:28 2013] [error] [client 111.93.158.52] File "/opt/python2.7/lib/python2.7/site-packages/pymongo-2.4.1-py2.7-linux-x86_64.egg/pymongo
/__init__.py", line 61, in <module>
[Wed Jan 30 11:40:28 2013] [error] [client 111.93.158.52] File "/opt/python2.7/lib/python2.7/site-packages/pymongo-2.4.1-py2.7-linux-x86_64.egg/pymongo
/connection.py", line 39, in <module>
[Wed Jan 30 11:40:28 2013] [error] [client 111.93.158.52] File "/opt/python2.7/lib/python2.7/site-packages/pymongo-2.4.1-py2.7-linux-x86_64.egg/pymongo
/mongo_client.py", line 44, in <module>
[Wed Jan 30 11:40:28 2013] [error] [client 111.93.158.52] File "/opt/python2.7/lib/python2.7/site-packages/pymongo-2.4.1-py2.7-linux-x86_64.egg/bson/__
init__.py", line 41, in <module>
[Wed Jan 30 11:40:28 2013] [error] [client 111.93.158.52] File "/opt/python2.7/lib/python2.7/site-packages/pymongo-2.4.1-py2.7-linux-x86_64.egg/bson/_c
bson.py", line 7, in <module>
[Wed Jan 30 11:40:28 2013] [error] [client 111.93.158.52] File "/opt/python2.7/lib/python2.7/site-packages/pymongo-2.4.1-py2.7-linux-x86_64.egg/bson/_c
bson.py", line 6, in __bootstrap__
[Wed Jan 30 11:40:28 2013] [error] [client 111.93.158.52] AttributeError: PyCapsule_Import "datetime.datetime_CAPI" is not valid
Here's the WSGI config in httpd.conf
LoadModule wsgi_module modules/mod_wsgi.so
WSGIScriptAlias /borg /var/www/webpy-app/borg/src/app.py/
WSGIPythonPath /opt/python2.7/lib/python2.7/site-packages/
Alias /borg/static /var/www/webpy-app/borg/src/static/
AddType text/html .py
<Directory /var/www/webpy-app/>
Order deny,allow
Allow from all
</Directory>
Is the error because of a python library incompatibility issue ? Am not sure. Any help will be greatly appreciated.
Figured this out by setting WSGIPythonHome to the appropriate location. WSGI was looking at an old Python library.

Flask framework on Openshift unable to load module

So I have created a flask application in OS from the OS quickstart on github. The app works great on my local system. when i push the app to OS it builds but I get an error 500 in the browser.
Any ideas or assistance would be appreciated.
Here is the source code from the application file:
#!/usr/bin/python import os
virtenv = os.environ['APPDIR'] + '/virtenv/'
os.environ['PYTHON_EGG_CACHE'] = os.path.join(virtenv, 'lib/python2.6/site-packages')
virtualenv = os.path.join(virtenv, 'bin/activate_this.py')
try:
execfile(virtualenv, dict(__file__=virtualenv))
except IOError:
pass
from run import app as application
Here is the source from the run.py file
from app import app
app.run(debug = True)
Here are the errors from the logs (Stripped the HASH ID for my site):
[Sun Aug 05 15:46:08 2012] [error] * Running on http://127.0.0.1:5000/
[Sun Aug 05 15:46:08 2012] [error] [client 127.3.153.129] mod_wsgi (pid=28484): Target WSGI script '/var/lib/stickshift/HASH-ID-HERE/app-root/runtime/repo/wsgi/application' cannot be loaded as Python module.
[Sun Aug 05 15:46:08 2012] [error] [client 127.3.153.129] mod_wsgi (pid=28484): Exception occurred processing WSGI script '/var/lib/stickshift/HASH-ID-HERE/app-root/runtime/repo/wsgi/application'.
[Sun Aug 05 15:46:08 2012] [error] [client 127.3.153.129] Traceback (most recent call last):
[Sun Aug 05 15:46:08 2012] [error] [client 127.3.153.129] File "/var/lib/stickshift/HASH-ID-HERE/app-root/runtime/repo/wsgi/application", line 13, in <module>
[Sun Aug 05 15:46:08 2012] [error] [client 127.3.153.129] from run import app as application
[Sun Aug 05 15:46:08 2012] [error] [client 127.3.153.129] File "/var/lib/stickshift/HASH-ID-HERE/app-root/runtime/repo/wsgi/run.py", line 2, in <module>
[Sun Aug 05 15:46:08 2012] [error] [client 127.3.153.129] app.run(debug = True)
[Sun Aug 05 15:46:08 2012] [error] [client 127.3.153.129] File "/var/lib/stickshift/HASH-ID-HERE/ws/virtenv/lib/python2.6/site-packages/Flask-0.9-py2.6.egg/flask/app.py", line 739, in run
[Sun Aug 05 15:46:08 2012] [error] [client 127.3.153.129] run_simple(host, port, self, **options)
[Sun Aug 05 15:46:08 2012] [error] [client 127.3.153.129] File "/var/lib/stickshift/HASH-ID-HERE/ws/virtenv/lib/python2.6/site-packages/Werkzeug-0.8.3-py2.6.egg/werkzeug/serving.py", line 613, in run_simple
[Sun Aug 05 15:46:08 2012] [error] [client 127.3.153.129] test_socket.bind((hostname, port))
[Sun Aug 05 15:46:08 2012] [error] [client 127.3.153.129] File "<string>", line 1, in bind
[Sun Aug 05 15:46:08 2012] [error] [client 127.3.153.129] error: [Errno 13] Permission denied
[Sun Aug 05 15:46:09 2012] [error] * Running on http://127.0.0.1:5000/
[Sun Aug 05 15:46:09 2012] [error] [client 127.3.153.129] mod_wsgi (pid=31302): Target WSGI script '/var/lib/stickshift/HASH-ID-HERE/app-root/runtime/repo/wsgi/application' cannot be loaded as Python module.
[Sun Aug 05 15:46:09 2012] [error] [client 127.3.153.129] mod_wsgi (pid=31302): Exception occurred processing WSGI script '/var/lib/stickshift/HASH-ID-HERE/app-root/runtime/repo/wsgi/application'.
[Sun Aug 05 15:46:09 2012] [error] [client 127.3.153.129] Traceback (most recent call last):
[Sun Aug 05 15:46:09 2012] [error] [client 127.3.153.129] File "/var/lib/stickshift/HASH-ID-HERE/app-root/runtime/repo/wsgi/application", line 13, in <module>
[Sun Aug 05 15:46:09 2012] [error] [client 127.3.153.129] from run import app as application
[Sun Aug 05 15:46:09 2012] [error] [client 127.3.153.129] File "/var/lib/stickshift/HASH-ID-HERE/app-root/runtime/repo/wsgi/run.py", line 2, in <module>
[Sun Aug 05 15:46:09 2012] [error] [client 127.3.153.129] app.run(debug = True)
[Sun Aug 05 15:46:09 2012] [error] [client 127.3.153.129] File "/var/lib/stickshift/HASH-ID-HERE/ws/virtenv/lib/python2.6/site-packages/Flask-0.9-py2.6.egg/flask/app.py", line 739, in run
[Sun Aug 05 15:46:09 2012] [error] [client 127.3.153.129] run_simple(host, port, self, **options)
[Sun Aug 05 15:46:09 2012] [error] [client 127.3.153.129] File "/var/lib/stickshift/HASH-ID-HERE/ws/virtenv/lib/python2.6/site-packages/Werkzeug-0.8.3-py2.6.egg/werkzeug/serving.py", line 613, in run_simple
[Sun Aug 05 15:46:09 2012] [error] [client 127.3.153.129] test_socket.bind((hostname, port))
[Sun Aug 05 15:46:09 2012] [error] [client 127.3.153.129] File "<string>", line 1, in bind
[Sun Aug 05 15:46:09 2012] [error] [client 127.3.153.129] error: [Errno 13] Permission denied
You should not be trying to run the Flask built in development server when hosting under mod_wsgi. Go back and check the mod_wsgi documentation in Flask as to what you are meant to be doing.
http://flask.pocoo.org/docs/deploying/mod_wsgi/
So I have finally figured out what was wrong with my code. I was missing a line in my run.py file so the incorrect file looked like this:
Incorrect file:
from app import app
app.run()
This is the corrected working file:
from app import app
if __name__ == "__main__": #Need this line for Openshift
app.run()
The if statement is apparently needed when deployed to production servers like Apache
Have you checked the following description from flask website at:
http://flask.pocoo.org/docs/deploying/mod_wsgi/#working-with-virtual-environments
Problem: application gives permission errors
Probably caused by your application running as the wrong user. Make sure the folders the application needs access to have the proper
privileges set and the application runs as the correct user (user and
group parameter to the WSGIDaemonProcess directive)

Categories