mod_wsgi error

69 views
Skip to first unread message

Justin Martin

unread,
Oct 13, 2015, 10:05:08 PM10/13/15
to modwsgi
I'm trying to get a stand alone server up and running and running into some difficulties. I'm receiving the error below. I'm also not too familiar with django and mod_wsgi in general so this might be a rookie mistake.

I'm running RedHat 6.6, apache 2.2.15, django 1.6.1, python 2.6.6, mod_wsgi 3.2

mod_wsgi(pid=<PID>): Target WSGI script '/path/to/my/application/wsgi.py' cannot be loaded as Python module.
mod_wsgi
(pid=<PID>): Exception occurred process WSGI script 'path/to/my/application/wsgi.py'.
Traceback (most recent call list): File /path/to/my/application/wsgi.py, line 14 in <module> From django.core.wsgi import get_wsgi_application
ImportError: no module name django.core.wsgi


When I run it as python wsgi.py it doesn’t seem to have an issue.

I will also put my .conf files below in case they are needed. I didn't edit the httpd.conf file but instead created a seperate conf file.

/etc/httpd/conf.d/myapplication.conf
Alias /static/ /path/to/myapplication

<Directory /path/to/myapplication>
Order deny,allow
Allow from all
</Directory>

WSGIScriptAlias /
/path/to/myapplication/wsgi.py
WSGIPythonPath /path/to

<Directory /path/to/myapplication>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</
Directory>

/etc/httpd/conf.d/wsgi.conf
<IfModule !wsgi_module>
LoadModule wsgi_module modules/mod_wsgi.so
</IfModule>

The weird thing is it is up and running on a few other servers with the same layout but those work and this one doesn't. I've been trying to come up with ideas but I'm kind of stuck and it might come to do with my lack of knowledge of mod_wsgi and django.

Thanks for any and all assistance.

Graham Dumpleton

unread,
Oct 13, 2015, 11:29:00 PM10/13/15
to mod...@googlegroups.com
Are you using a Python virtual environment and are you installing Django into the Python virtual environment if you are, or is Django installed into system wide Python installation?

Also, check what version of Python mod_wsgi is actually compiled for by running checks in:



What do you get?

Graham

--
You received this message because you are subscribed to the Google Groups "modwsgi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to modwsgi+u...@googlegroups.com.
To post to this group, send email to mod...@googlegroups.com.
Visit this group at http://groups.google.com/group/modwsgi.
For more options, visit https://groups.google.com/d/optout.

Justin Martin

unread,
Oct 14, 2015, 3:10:19 PM10/14/15
to modwsgi
Graham,

I'm not using python in a virtual environment no.

I ran the checks and this is what was returned.

linux_vdso.so.1 => (0x00007fff4c6ae000)
libpython2
.6.so.1.0 => /usr/lib64/libpython2.6.so.1.0 (0x00007fb7830e0000)
libpthread
.so.0 => /lib64/libpthread.so.0 (0x00007fb782ec30000)
libdl
.so.2 => /lib64/libdl.so.2 (0x00007fb782cbe000)
libutil
.so.1 => /lib64/libutil.so.1 (0x00007fb782abb000)
libm
.so.6 => /lib64/libm.so.6 (0x00007fb782837000)
libc
.so.6 => /lib64/libc.so.6 (0x00007fb782402000)
/lib64/ld-linux-x86-64.so.2 (0x000003ad6c00000)

sys.version = '2.6.6 (r266:84292, Nov 21 2013, 10:50:32) \n[GCC 4.4.7 21020313 (Red Hat 4.4.7-4)]'
sys
.prefix = '/usr'


Justin

Graham Dumpleton

unread,
Oct 19, 2015, 11:30:28 PM10/19/15
to mod...@googlegroups.com
Sorry for the slow reply, been travelling for work the last couple of weeks.

From the Python interpreter, what do you get if you go:

$ python
Python 2.7.10 (default, Jul 14 2015, 19:46:27)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
>>> django.get_version()
‘1.7.1'

This will validate Django is actually installed, but also tell you how old of a Django version you have.

The wsgi.py code you have likely need Django 1.4 (???) or newer.

Am wondering whether you have a really old version of Django installed from a system package, rather than you having pip installed it yourself.

Graham

Justin Martin

unread,
Oct 20, 2015, 12:09:55 PM10/20/15
to mod...@googlegroups.com

No worries I was just making sure the post didn't get lost. I did the django.get_version() and it returned 1.6.1. I'm using apache 2.2 and I shouldn't have to use Require all granted and I get a authtype not set. I should be using the order and granted correct?

Thanks,
Justin

You received this message because you are subscribed to a topic in the Google Groups "modwsgi" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/modwsgi/ZnHn8AYnAbg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to modwsgi+u...@googlegroups.com.

Graham Dumpleton

unread,
Oct 20, 2015, 5:09:08 PM10/20/15
to mod...@googlegroups.com
Correct, you would use something like:

    Order allow,deny
    Allow from all

within the Directory block set up to allow access to the directory containing the WSGI script file.

As this is Red Hat, maybe the issue is a SELinux issue restrictions on Apache, although since you aren’t using a Python virtual environment, if Django is installed in system wide Python it should be accessible.

At the Python interpreter, what do you get for:

    import django
    print django.__file__

Graham

Justin Martin

unread,
Oct 21, 2015, 9:47:13 PM10/21/15
to mod...@googlegroups.com

I got /usr/lib/python2.6/site-packages/django/__init__.pyc

I am pretty sure I'm not using a virtual environment but I'd there a way to tell if django is installed in system wide python? I am not sure if django was installed via rpm or from the repo or how it was installed as it was already installed

Graham Dumpleton

unread,
Oct 22, 2015, 7:03:48 AM10/22/15
to mod...@googlegroups.com
What do you get if you use the test WSGI application in:


to print out what sys.path is inside of the WSGI application process?

Graham

Justin Martin

unread,
Oct 22, 2015, 7:12:30 AM10/22/15
to mod...@googlegroups.com

Graham,
I got what's pasted below

sys.version = '2.6.6 (r266:84292, Nov 21 2013, 10:50:32) \n[GCC 4.4.7 21020313 (Red Hat 4.4.7-4)]'
sys.prefix = '/usr'

Graham Dumpleton

unread,
Oct 22, 2015, 7:13:49 AM10/22/15
to mod...@googlegroups.com
The second program that outputs sys.path, not the first.

import sys

def application(environ, start_response):
    status
= '200 OK'
    output
= 'sys.path = %s' % repr(sys.path)

    response_headers
= [('Content-type', 'text/plain'),
                       
('Content-Length', str(len(output)))]
    start_response
(status, response_headers)

   
return [output]


Graham

Justin Martin

unread,
Oct 23, 2015, 9:50:20 AM10/23/15
to modwsgi
sys.path= ['/path/to/myapplication', '/usr/lib64/python26.zip','/usr/lib64/python2.6/','/usr/lib64/python2.6/plat-linux2','/usr/lib64/python2.6/lib-tk','/usr/lib64/python2.6/lib-old','/usr/lib64/python2.6/lib-dynload','/usr/lib64/python2.6/site-packages','/usr/lib64/python2.6/site-packages/gtk2-0','/usr/lib/python2.6/site-packages','/usr/lib/python2.6/site-packages/setuptools-0.6cll-py2.6.egg-info']

Graham Dumpleton

unread,
Oct 25, 2015, 9:10:50 PM10/25/15
to mod...@googlegroups.com
Since '/usr/lib/python2.6/site-packages’ does appear to be in sys.path, what do you get for:

ls -las /usr/lib/python2.6/site-packages/django

Then try a simple WSGI hello world that does:

import sys
import os


def application(environ, start_response):
    status = '200 OK'
    output = 'sys.path = %s' % repr(os.listdir('/usr/lib/python2.6/site-packages/django')

    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)

    return [output]

The latter should show whether the Apache process has access rights to the directory to see in it and whether file system permissions are okay or whether there may be SELinux restrictions coming into play.

Graham

Justin Martin

unread,
Oct 28, 2015, 6:54:03 AM10/28/15
to mod...@googlegroups.com

Graham,
That did it. I didn't have the permissions set correctly on that folder. Once I updated those everything started displaying correctly. Thought I had looked there before but apparently not.

Thanks for all your help in tracking this issue down

Graham Dumpleton

unread,
Oct 28, 2015, 6:56:43 AM10/28/15
to mod...@googlegroups.com
Likely you had a restrictive umask setting when installing Django, if you had installed it using pip or its own setup.py file.

Graham

Justin Martin

unread,
Apr 11, 2016, 12:02:56 PM4/11/16
to mod...@googlegroups.com
Hey Graham,

Coming back to you again because I'm having issues with a django installation. I followed what we did last time and was still having issues. I was hoping your more trained eye would be helpful.

I was able to do the hello word and that came back fine. This is what I have so far

sys.path = ['/usr/lib/power', '/usr/lib64/python26.zip','/usr/lib64/python2.6','/usr/lib64/plat-linux2','/usr/lib64/lib-tk','/usr/lib64/lib-old','/usr/lib64/lib-dynload','/usr/lib64/site-packages','/usr/lib64/site-packages/gtk-20','/usr/lib/python2.6/sitepackages']

sys.version = '2.6.6 (v266:84292, May 22 2015, 08:34:51)'

sys.prefix = '/usr'

Thanks in advance.

Graham Dumpleton

unread,
Apr 11, 2016, 6:49:11 PM4/11/16
to mod...@googlegroups.com
What is the current issues you are having? What are the error messages? I don’t want to assume it is the same issue.

Justin Martin

unread,
Apr 12, 2016, 6:40:08 PM4/12/16
to mod...@googlegroups.com

Hi Graham,

It was the same issue but no worries. They blew away the server I was working on and I'm going to another project anyway. I was trying to get them in a good position but it'll have to be done at some other point.

Thanks again for your quick response and being willing to assist.

Justin

Reply all
Reply to author
Forward
0 new messages