Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an apache2 server with active mod-wsgi, but I can't get the environment variable PYTHON_EGG_CACHE.
Here the important lines out of my virtualhost.conf:

    DAV svn
    SVNParentPath /var/svn
    SVNListParentPath Off

    WSGIProcessGroup sites
    WSGIApplicationGroup %{GLOBAL}
    SetEnv PYTHON_EGG_CACHE /var/trac/eggs

    AuthType Basic
    AuthName "Restricted SVN"
    AuthBasicProvider wsgi
    WSGIAuthUserScript /var/trac/cgi-bin/acctmgr_auth.wsgi
    Require valid-user

And here the acctmgr_auth.wsgi:

import os, sys

from trac.env import open_environment, Environment

acct_mgr = None

def check_password(environ, user, password):
    global acct_mgr

    # Try loading the env from the global cache, addit it if needed
    env = open_environment(environ['trac.env_path'], use_cache=True)

    if acct_mgr is None:
        from acct_mgr.api import AccountManager
        acct_mgr = AccountManager

    if acct_mgr(env).check_password(user, password):
        return True
        return False

def groups_for_user(environ, user):
    return ['']

The single environ['PYTHON_EGG_CACHE'] is just a test, but I get a



I also tried following, but I get the same error as above:

        RewriteCond ${lowercase:%{REQUEST_URI}} ^/svn/([^/]+)
        RewriteRule . - [E=trac.svn_path:/var/trac/envs/%1]

What is wrong?

Thanks for any advices.

EDIT: After some resarch I think I found the problem. The mod_dav is configured for the location /svn and it processes the request immediately, so the rewritecond and rewriterule will be ignored.
Is there any possibility to set environment variables with mod_dav?

share|improve this question

This is how I did it on my django site, where the path is set in the apache file (as MY_PATH). Notice that I copy it into the os.environ variable.

import os, sys, django.core.handlers.wsgi
_application = django.core.handlers.wsgi.WSGIHandler()

def application(environ, start_response):

    path = environ['MY_PATH']
    if path not in sys.path:

    os.environ['MY_PATH'] = environ['MY_PATH']
    from django.conf import settings
    settings.DEBUG = True

    return _application(environ, start_response)

Since I copied the environment variable to the os.environ, I can now use it (for example) in the settings file. Note that I have set all the os.environ variables before including the settings. In the settings I get it like so:

import os
PATH = os.environ['MY_PATH']
share|improve this answer

SetEnv usually only sets process environment variables when using CGI. For mod_wsgi, SetEnv variables go into per request WSGI environment and not the process environment.
Thus they aren't accessible from global scope in WSGI script and even in the application callable, you have to access them from environ dictionary passed as argument.

share|improve this answer
up vote 1 down vote accepted

I found a solution by using the content of environ['REQUEST_URI'] and check it in the python file.
More details can you find here:

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.