Greg
Greg

Reputation: 10352

How do I set a python path when using WSGIAuthUserScript?

I'm trying to implement Apache Basic Auth using mod_wsgi's WSGIAuthUserScript directive, and I can't figure out how to specify a python path. I'm using Django for the authentication, as detailed here, and I'm getting errors like:

Traceback (most recent call last):
   File "/path-to-site/src/project/wsgi.py", line 21, in <module>
     from django.contrib.auth.handlers.modwsgi import check_password
 ImportError: No module named django.contrib.auth.handlers.modwsgi

My WSGIDaemonProcess directive uses the python-path option (pointing to a virtualenv's site-packages) but there doesn't seem to be a similar option for WSGIAuthUserScript. I've tried setting WSGIPythonPath, and setting the application-group option for WSGIAuthUserScript, but neither helped.

Upvotes: 2

Views: 704

Answers (2)

Sebastien DA ROCHA
Sebastien DA ROCHA

Reputation: 472

I had similar problem, WSGIAuthUserScript does not use WSGIPythonPath or WSGIPythonHome nor process group. 2 solutions that worked for me:

Solution 1) compile mod_wsgi in your virtual env

# load your virtual environment
. bin/activate
# compiles AXXS needed by mod WSGI
pip install mod_wsgi-httpd
# Compile mod WSGI
pip install mod-wsgi

Install the mod_wsgi module in apache (CentOS & Co)

mod_wsgi-express install-module > /etc/httpd/conf.modules.d/25-wsgi.conf

Install the mod_wsgi module in apache (Debian & Co)

mod_wsgi-express install-module > /etc/apache2/mods-available/wsgi.conf
a2enmod wsgi

All your script should use your virtual env now.

Solution 2) load your venv within your auth script

python_home = "/myt_venv_path/"
sys.path.append(python_home)

# Needed by WSGIAuthUserScript
activate_this = python_home + '/bin/activate_this.py'
with open(activate_this) as venv:
    exec(venv.read(), {'__file__': activate_this})

Upvotes: 0

Graham Dumpleton
Graham Dumpleton

Reputation: 58543

WSGIPythonPath should have worked. That or setting sys.path in the WSGI script file itself. What are you setting it to? Where is django installed? Does the user that Apache runs as have read permission down into where you have it installed?

Upvotes: 1

Related Questions