webpy with mod_wsgi on apache2 - weird pymongo bson error - python

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.

Related

A Django service giving Internal server error

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?

Exception occurred processing WSGI script - WAMP Server

Installed Python and Django on a Windows Server 2008 R2 Wamp Machine. Everything's fine, except a ported version of a django/python website which were on a LAMP machine previously.
500 internal server error when accessing the vhost via web browser
I get this error log from apache:
[Tue Aug 06 12:29:27 2013] [error] [client 127.0.0.1] mod_wsgi (pid=1788): Exception occurred processing WSGI script 'C:/Wamp/www/mysite_com/mysite_com.wsgi'.
[Tue Aug 06 12:29:27 2013] [error] [client 127.0.0.1] Traceback (most recent call last):
[Tue Aug 06 12:29:27 2013] [error] [client 127.0.0.1] File "C:\\Python27\\lib\\site-packages\\django\\core\\handlers\\wsgi.py", line 255, in __call__
[Tue Aug 06 12:29:27 2013] [error] [client 127.0.0.1] response = self.get_response(request)
[Tue Aug 06 12:29:27 2013] [error] [client 127.0.0.1] File "C:\\Python27\\lib\\site-packages\\django\\core\\handlers\\base.py", line 178, in get_response
[Tue Aug 06 12:29:27 2013] [error] [client 127.0.0.1] response = self.handle_uncaught_exception(request, resolver, sys.exc_info())
[Tue Aug 06 12:29:27 2013] [error] [client 127.0.0.1] File "C:\\Python27\\lib\\site-packages\\django\\core\\handlers\\base.py", line 220, in handle_uncaught_exception
[Tue Aug 06 12:29:27 2013] [error] [client 127.0.0.1] if resolver.urlconf_module is None:
[Tue Aug 06 12:29:27 2013] [error] [client 127.0.0.1] File "C:\\Python27\\lib\\site-packages\\django\\core\\urlresolvers.py", line 342, in urlconf_module
[Tue Aug 06 12:29:27 2013] [error] [client 127.0.0.1] self._urlconf_module = import_module(self.urlconf_name)
[Tue Aug 06 12:29:27 2013] [error] [client 127.0.0.1] File "C:\\Python27\\lib\\site-packages\\django\\utils\\importlib.py", line 35, in import_module
[Tue Aug 06 12:29:27 2013] [error] [client 127.0.0.1] __import__(name)
[Tue Aug 06 12:29:27 2013] [error] [client 127.0.0.1] ImportError: No module named urls
This is my .wsgi app:
import os, sys
sys.path.append('c:/Wamp/www/')
os.environ ['DJANGO_SETTINGS_MODULE'] = 'mysite_com.settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
And my apache vhosts
<VirtualHost *:80>
ServerName mysite.com
ServerAlias www.mysite.com
DocumentRoot "C:/Wamp/www/mysite_com/"
WSGIScriptAlias / "C:/Wamp/www/mysite_com/mysite_com.wsgi"
</VirtualHost>
folder structure
\www
\mysite_com
\__init__.py
\settings.py
\urls.py
\manage.py
\mysite_com.wsgi
Any advice?
Thanks
You're adding the site path to your system path wrong. See in Linux you would use forward slashes '/' while in windows (which you seem to be using) backward slashes '\'. Of course, you need to double them up so it won't be rendered as escape strings:
sys.path.append('C:\\wamp\\www')
of course, it would be much easier like this:
sys.path.append(r'C:\wamp\www')
And see - your server can find the wsgi application because you told apache where to find it, so it complains about the next module that it can't find (which just happens to be urls.py). I already answered in a comment but I thought an explanation of why you saw the error that specific way would help.
p.s.
If that still doesn't work you might need to append the path to your actual application:
sys.path.append(r'C:\Wamp\www\mysite_com')

Internal Server Error Apache and WSGI (With Flask)

(sorry fist question and not yet answered anything, I'll get to it!)
I am trying to setup Flask with Apache2 and mod_wsgi in an ubuntu 12.04 virtual machine, mainly so that I know how to do it in the future when I come to deploying a Flask application. Just so that you guys know, I am new to Python and Flask, but I am familiar with PHP, and as a consequence general programming practices.
I am following this tutorial to setup Flask. I have successfully setup the test application defined in the tutorial, however when I try to setup an existing application using the tutorial I get the following error:
Internal Server Error
The server encountered an internal error and was unable to complete your request.
Either the server is overloaded or there is an error in the application.
Here is my app.py file, I suspect there is an error here but I can't find it, I added in the app run code from the tutorial In hopes it would work but it didn't, I got the same error and I could never get an error log, so I switched back to "app.run()" and when I restart apache I get an error log:
import flask
import settings
# Views
from main import Main
from login import Login
from remote import Remote
from music import Music
app = flask.Flask(__name__)
app.secret_key = settings.secret_key
# Routes
app.add_url_rule('/',
view_func=Main.as_view('main'),
methods=["GET"])
app.add_url_rule('/<page>/',
view_func=Main.as_view('page'),
methods=["GET"])
app.add_url_rule('/login/',
view_func=Login.as_view('login'),
methods=["GET", "POST"])
app.add_url_rule('/remote/',
view_func=Remote.as_view('remote'),
methods=['GET', 'POST'])
app.add_url_rule('/music/',
view_func=Music.as_view('music'),
methods=['GET'])
#app.errorhandler(404)
def page_not_found(error):
return flask.render_template('404.html'), 404
#app.debug = True
app.run()
#if __name__ == '__main__':
#"Are we in the __main__ scope? Start test server."
#app.run(host='0.0.0.0',port=5000,debug=True)
And here is the error.log file that is returned. I have read it b
[Sat Jun 29 11:59:23 2013] [error] [client 127.0.0.1] mod_wsgi (pid=5739): Target WSGI script '/home/carwyn/public_html/wsgi/learningflask.wsgi' cannot be loaded as Python module.
[Sat Jun 29 11:59:23 2013] [error] [client 127.0.0.1] mod_wsgi (pid=5739): Exception occurred processing WSGI script '/home/carwyn/public_html/wsgi/learningflask.wsgi'.
[Sat Jun 29 11:59:23 2013] [error] [client 127.0.0.1] Traceback (most recent call last):
[Sat Jun 29 11:59:23 2013] [error] [client 127.0.0.1] File "/home/carwyn/public_html/wsgi/learningflask.wsgi", line 3, in <module>
[Sat Jun 29 11:59:23 2013] [error] [client 127.0.0.1] from app import app as application
[Sat Jun 29 11:59:23 2013] [error] [client 127.0.0.1] File "/home/carwyn/public_html/apps/learningflask/app.py", line 35, in <module>
[Sat Jun 29 11:59:23 2013] [error] [client 127.0.0.1] app.run()
[Sat Jun 29 11:59:23 2013] [error] [client 127.0.0.1] File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 772, in run
[Sat Jun 29 11:59:23 2013] [error] [client 127.0.0.1] run_simple(host, port, self, **options)
[Sat Jun 29 11:59:23 2013] [error] [client 127.0.0.1] File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 710, in run_simple
[Sat Jun 29 11:59:23 2013] [error] [client 127.0.0.1] inner()
[Sat Jun 29 11:59:23 2013] [error] [client 127.0.0.1] File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 692, in inner
[Sat Jun 29 11:59:23 2013] [error] [client 127.0.0.1] passthrough_errors, ssl_context).serve_forever()
[Sat Jun 29 11:59:23 2013] [error] [client 127.0.0.1] File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 436, in serve_forever
[Sat Jun 29 11:59:23 2013] [error] [client 127.0.0.1] HTTPServer.serve_forever(self)
[Sat Jun 29 11:59:23 2013] [error] [client 127.0.0.1] File "/usr/lib/python2.7/SocketServer.py", line 225, in serve_forever
[Sat Jun 29 11:59:23 2013] [error] [client 127.0.0.1] r, w, e = select.select([self], [], [], poll_interval)
[Sat Jun 29 11:59:23 2013] [error] [client 127.0.0.1] error: (4, 'Interrupted system call')
If you need any more information then I would be happy to provide it, I would appreciate all the help I can get.
EDIT:
Here is my learningflask.wsgi file:
import sys
sys.path.insert(0, '/home/carwyn/public_html/apps/learningflask')
from app import app as application
And here is my available-sites apache file-thing (called learningflask), it pretty much just follows the tutorial one but is set up for the tutorial application:
<VirtualHost *:8081>
# ---- Configure VirtualHost Defaults ----
ServerAdmin carwynjohnnelson#aol.com
DocumentRoot /home/carwyn/public_html/http/learningflask/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /home/carwyn/public_html/http/learningflask/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
# ---- Configure WSGI Listener(s) ----
WSGIDaemonProcess learningflask user=www-data group=www-data threads=5
WSGIScriptAlias /learningflask /home/carwyn/public_html/wsgi/learningflask.wsgi
<Directory /home/carwyn/public_html/http/learningflask>
WSGIProcessGroup learningflask
WSGIApplicationGroup %{GLOBAL}
Order deny,allow
Allow from all
</Directory>
# ---- Configure Logging ----
ErrorLog /home/carwyn/public_html/logs/error.log
LogLevel warn
CustomLog /home/carwyn/public_html/logs/access.log combined
</VirtualHost>
SECOND EDIT:
I hope this might help, I removed the app.run and reloaded the page and I get the error. Then I looked in my previously cleared error log and get nothing. So i restarted apache and looked in my error log and I get this:
[Sat Jun 29 21:33:19 2013] [error] [client 127.0.0.1] mod_wsgi (pid=5908): Target WSGI script '/home/carwyn/public_html/wsgi/learningflask.wsgi' cannot be loaded as Python module.
[Sat Jun 29 21:33:19 2013] [error] [client 127.0.0.1] mod_wsgi (pid=5908): Exception occurred processing WSGI script '/home/carwyn/public_html/wsgi/learningflask.wsgi'.
[Sat Jun 29 21:33:19 2013] [error] [client 127.0.0.1] Traceback (most recent call last):
[Sat Jun 29 21:33:19 2013] [error] [client 127.0.0.1] File "/home/carwyn/public_html/wsgi/learningflask.wsgi", line 3, in <module>
[Sat Jun 29 21:33:19 2013] [error] [client 127.0.0.1] from app import app as application
[Sat Jun 29 21:33:19 2013] [error] [client 127.0.0.1] File "/home/carwyn/public_html/apps/learningflask/app.py", line 35, in <module>
[Sat Jun 29 21:33:19 2013] [error] [client 127.0.0.1] #app.run()
[Sat Jun 29 21:33:19 2013] [error] [client 127.0.0.1] File "/usr/local/lib/python2.7/dist-packages/flask/app.py", line 772, in run
[Sat Jun 29 21:33:19 2013] [error] [client 127.0.0.1] run_simple(host, port, self, **options)
[Sat Jun 29 21:33:19 2013] [error] [client 127.0.0.1] File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 710, in run_simple
[Sat Jun 29 21:33:19 2013] [error] [client 127.0.0.1] inner()
[Sat Jun 29 21:33:19 2013] [error] [client 127.0.0.1] File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 692, in inner
[Sat Jun 29 21:33:19 2013] [error] [client 127.0.0.1] passthrough_errors, ssl_context).serve_forever()
[Sat Jun 29 21:33:19 2013] [error] [client 127.0.0.1] File "/usr/local/lib/python2.7/dist-packages/werkzeug/serving.py", line 436, in serve_forever
[Sat Jun 29 21:33:19 2013] [error] [client 127.0.0.1] HTTPServer.serve_forever(self)
[Sat Jun 29 21:33:19 2013] [error] [client 127.0.0.1] File "/usr/lib/python2.7/SocketServer.py", line 225, in serve_forever
[Sat Jun 29 21:33:19 2013] [error] [client 127.0.0.1] r, w, e = select.select([self], [], [], poll_interval)
[Sat Jun 29 21:33:19 2013] [error] [client 127.0.0.1] error: (4, 'Interrupted system call')
You should not be calling:
app.run()
This is starting Flask's own HTTP server within the Apache process.
There was a reason it was inside of an if() statement checking to see whether __name__ was '__main__'. That was to ensure it was only called when the script was run from command line Python interpreter. You do not want it to be run under Apache.

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.

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