[mod_python] Restricted Mode

Graham Dumpleton grahamd at dscpl.com.au
Wed Nov 8 15:58:57 EST 2006

Dr R. Sanderson wrote ..
> Hi all,
> We use 4Suite for XSLT processing within mod_python, however when we 
> try to use functions within the stylesheets, it complains that python is
> in restricted mode.
> We're using Python 2.4.3 and mod_python 3.2.10, so it's not the previous
> problem that was putting it into restricted mode fixed circa 
> Python 2.3/mod_python 3.1
> It doesn't /always/ do this, it seems to flip into it sometimes. 
> Possibly when the httpd reloads, but we're not sure about that.
> Given that, creating a minimal breaking script to demonstrate is quite
> complicated.
> Any help or suggestions appreciated!

I don't know about any fixes in mod_python 3.1.X related to restricted mode,
but there were some changes in mod_python 3.2.10 related to it. Even when
using mod_python 3.2.10, for it to work you still have to do one extra step
which is to force all the requests handlers which use the problematic package
to run within the context of the 'main_interpreter' instance. To do this, you
must use:

  PythonInterpreter main_interpreter

in conjunction with the Python*Handler directive which you are using to
trigger your mod_python handlers to run.

To confirm that your code is working within the context of the correct
interpreter, log the value of 'req.interpreter' into the Apache error log from
your handler.

There is some history of the issue in:


Please try this and then let us know if it works or not so we know whether this
can be given as a solution to others in the future.


More information about the Mod_python mailing list