(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.
Related
I am trying to install mod_wsgi on apache2, on ubuntu.
So I install libapache2-mod-wsgi package, I activate him with a2enmod.
I got a web site (languageAnalyz), that I am trying to use with mod_wsgi.
When I call localhost/languageAnalyz, I got an error 500.
In apache2 log, I can see this :
[Sun Aug 25 11:28:21 2013] [error] [client 127.0.0.1] mod_wsgi (pid=4993): Target WSGI script '/var/www/languageAnalyz/test-wsgi.py' cannot be loaded as Python module.
[Sun Aug 25 11:28:21 2013] [error] [client 127.0.0.1] mod_wsgi (pid=4993): SystemExit exception raised by WSGI script '/var/www/languageAnalyz/test-wsgi.py' ignored.
[Sun Aug 25 11:28:21 2013] [error] [client 127.0.0.1] Traceback (most recent call last):
[Sun Aug 25 11:28:21 2013] [error] [client 127.0.0.1] File "/var/www/languageAnalyz/test-wsgi.py", line 10, in <module>
[Sun Aug 25 11:28:21 2013] [error] [client 127.0.0.1] WSGIServer(app).run()
[Sun Aug 25 11:28:21 2013] [error] [client 127.0.0.1] File "/usr/local/lib/python2.7/dist-packages/flup/server/fcgi.py", line 112, in run
[Sun Aug 25 11:28:21 2013] [error] [client 127.0.0.1] sock = self._setupSocket()
[Sun Aug 25 11:28:21 2013] [error] [client 127.0.0.1] File "/usr/local/lib/python2.7/dist-packages/flup/server/fcgi_base.py", line 997, in _setupSocket
[Sun Aug 25 11:28:21 2013] [error] [client 127.0.0.1] req.run()
[Sun Aug 25 11:28:21 2013] [error] [client 127.0.0.1] File "/usr/local/lib/python2.7/dist-packages/flup/server/fcgi_base.py", line 572, in run
[Sun Aug 25 11:28:21 2013] [error] [client 127.0.0.1] self._end(appStatus, protocolStatus)
[Sun Aug 25 11:28:21 2013] [error] [client 127.0.0.1] File "/usr/local/lib/python2.7/dist-packages/flup/server/fcgi_base.py", line 601, in _end
[Sun Aug 25 11:28:21 2013] [error] [client 127.0.0.1] sys.exit(appStatus)
[Sun Aug 25 11:28:21 2013] [error] [client 127.0.0.1] SystemExit: 0
I googled this error, and I find lot of solutions (most of the times for Django project).
What I undsertand, is that I need to create a __init__.py file.
What I did, here is my __init__.py file :
__all__ = ['app','get_size_dir','get_nbrf_dir','getStats'] #name of my functions
import index # my three python files
import analyz
import test-wsgi
In the __all__ list, this is the name of the functions in the three files.
I am just trying to launch test-wsgi.py, and get the same error 500.
Here is my test-wsgi.py file :
import os,sys
sys.path.append(os.path.dirname(__file__))
from cgi import escape,parse_qs
from flup.server.fcgi import WSGIServer
def app(environ, start_response):
start_response('200 OK',[('Content-Type','text/plain; charset=utf-8')])
yield "hello world!"
WSGIServer(app).run()
So what's wrong ?
Thank you,
Edit :
here is my apache2 conf :
WSGIPythonPath /var/www/languageAnalyz
<VirtualHost *:80>
...
<Directory /var/www/languageAnalyz/>
Options +Indexes ExecCGI FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
DirectoryIndex index.py
SetHandler wsgi-script
</Directory>
...
</VirtualHost>
Edit_bis :
So I try to do as I read on django doc.
I change my apache2 conf to :
WSGIPythonPath /var/www/languageAnalyz
<VirtualHost *:80>
...
WSGIScriptAlias /IPA /var/www/languageAnalyz/testwsgi.py
<Directory /var/www/languageAnalyz/>
Options +Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
DirectoryIndex testwsgi.py
</Directory>
...
</VirtualHost>
I restart apache2, and I got the same error, and one more before :
[Sun Aug 25 12:47:18 2013] [notice] caught SIGTERM, shutting down
[Sun Aug 25 12:47:19 2013] [notice] FastCGI: wrapper mechanism enabled (wrapper: /usr/lib/apache2/suexec)
[Sun Aug 25 12:47:19 2013] [notice] FastCGI: process manager initialized (pid 7879)
[Sun Aug 25 12:47:19 2013] [notice] mod_python: Creating 8 session mutexes based on 150 max processes and 0 max threads.
[Sun Aug 25 12:47:19 2013] [notice] mod_python: using mutex_directory /tmp
[Sun Aug 25 12:47:19 2013] [warn] mod_wsgi: Compiled for Python/2.7.3.
[Sun Aug 25 12:47:19 2013] [warn] mod_wsgi: Runtime using Python/2.7.4.
[Sun Aug 25 12:47:19 2013] [notice] Apache/2.2.22 (Ubuntu) mod_fastcgi/mod_fastcgi-SNAP-0910052141 PHP/5.4.9-4ubuntu2.2 mod_python/3.3.1 Python/2.7.4 mod_ruby/1.2.6 Ruby/1.8.7(2012-02-08) mod_wsgi/3.4 configured$
[Sun Aug 25 12:47:19 2013] [error] WSGIServer: missing FastCGI param REQUEST_METHOD required by WSGI!
[Sun Aug 25 12:47:19 2013] [error] WSGIServer: missing FastCGI param SERVER_NAME required by WSGI!
[Sun Aug 25 12:47:19 2013] [error] WSGIServer: missing FastCGI param SERVER_PORT required by WSGI!
[Sun Aug 25 12:47:19 2013] [error] WSGIServer: missing FastCGI param SERVER_PROTOCOL required by WSGI!
[Sun Aug 25 12:47:19 2013] [error] Status: 200 OK\r
[Sun Aug 25 12:47:19 2013] [error] Content-Type: text/plain; charset=utf-8\r
[Sun Aug 25 12:47:19 2013] [error] \r
[Sun Aug 25 12:47:19 2013] [error] hello world!
[Sun Aug 25 12:47:19 2013] [error] [client 127.0.0.1] mod_wsgi (pid=7884): Target WSGI script '/var/www/languageAnalyz/testwsgi.py' cannot be loaded as Python module.
[Sun Aug 25 12:47:19 2013] [error] [client 127.0.0.1] mod_wsgi (pid=7884): SystemExit exception raised by WSGI script '/var/www/languageAnalyz/testwsgi.py' ignored.
[Sun Aug 25 12:47:19 2013] [error] [client 127.0.0.1] Traceback (most recent call last):
[Sun Aug 25 12:47:19 2013] [error] [client 127.0.0.1] File "/var/www/languageAnalyz/testwsgi.py", line 10, in <module>
[Sun Aug 25 12:47:19 2013] [error] [client 127.0.0.1] WSGIServer(app).run()
[Sun Aug 25 12:47:19 2013] [error] [client 127.0.0.1] File "/usr/local/lib/python2.7/dist-packages/flup/server/fcgi.py", line 112, in run
[Sun Aug 25 12:47:19 2013] [error] [client 127.0.0.1] sock = self._setupSocket()
[Sun Aug 25 12:47:19 2013] [error] [client 127.0.0.1] File "/usr/local/lib/python2.7/dist-packages/flup/server/fcgi_base.py", line 997, in _setupSocket
[Sun Aug 25 12:47:19 2013] [error] [client 127.0.0.1] req.run()
[Sun Aug 25 12:47:19 2013] [error] [client 127.0.0.1] File "/usr/local/lib/python2.7/dist-packages/flup/server/fcgi_base.py", line 572, in run
[Sun Aug 25 12:47:19 2013] [error] [client 127.0.0.1] self._end(appStatus, protocolStatus)
[Sun Aug 25 12:47:19 2013] [error] [client 127.0.0.1] File "/usr/local/lib/python2.7/dist-packages/flup/server/fcgi_base.py", line 601, in _end
[Sun Aug 25 12:47:19 2013] [error] [client 127.0.0.1] sys.exit(appStatus)
[Sun Aug 25 12:47:19 2013] [error] [client 127.0.0.1] SystemExit: 0
Edit_ter :
Ok, I just successfully launch testwsgi.py. I change my app function into application, and I add some lines at the end :
if __name__ == '__main__':
from wsgiref.simple_server import make_server
server = make_server('localhost', 8080, application)
server.serve_forever()
I event don't know, why it's working, why it was not working before. ... And now I got some problem to open files, with their path (config files, or templates files ...)
[Sun Aug 25 13:10:51 2013] [error] [client 127.0.0.1] File "/var/www/languageAnalyz/analyz.py", line 22, in getStats
[Sun Aug 25 13:10:51 2013] [error] [client 127.0.0.1] flangs=open('config/languages.yml')
I try with absolute path, it didn't work too ...
You would appear to be following the wrong documentation for starters. For mod_wsgi use:
https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/modwsgi/
You appear to be using documentation for FASTCGI deployment.
Also, you cannot do:
import test-wsgi
A Python module name cannot have '-' in it.
In summary, go reread (or read) the Django documentation on deployment.
For me the problem was wsgi python version mismatch. I was using python 3, so:
$ sudo apt-get remove libapache2-mod-python libapache2-mod-wsgi
$ sudo apt-get install libapache2-mod-wsgi-py3
I had the same problem for a differnt file and making the file world executable fixed it for me. You would of course want to lock it down to the required user after you have narrowed this down as your issue:
chmod a+x test-wsgi.py
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')
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.
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.
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)