[mod_python] python path and 3.3

Graham Dumpleton grahamd at dscpl.com.au
Sat Dec 2 01:22:44 EST 2006


On 02/12/2006, at 8:41 AM, Graham Dumpleton wrote:

>
> On 02/12/2006, at 12:03 AM, Clodoaldo wrote:
>
>> I'm trying to import a module with both the third and fourth
>> techniques you described but I'm having errors.
>>
>> This is the Virtual host config:
>>
>>    ServerName carconsumption.s0
>>    DocumentRoot /var/www/html/carconsumption.com
>>    SetHandler mod_python
>>    PythonHandler mod_python.publisher
>>    PythonDebug On
>>    PythonOption mod_python.importer.path "['~/mod']"
>>    PythonImport db_connection carconsumption.s0
>>
>> The module "constants" is in the mod directory under the document  
>> root:
>>
>> [cpn at s0 mod]$ pwd
>> /var/www/html/carconsumption.com/mod
>> [cpn at s0 mod]$ ll constants.py
>> -rwxr----- 1 cpn apache 28675 Nov 29 17:42 constants.py
>> [cpn at s0 mod]$ ll -d ../mod
>> drwxrws--- 2 cpn apache 4096 Dec  1 12:26 ../mod
>>
>> Third technique. index.py contains:
>>
>> from mod_python import apache
>> C = apache.import_module('~/mod/constants.py')
>>
>> The error output:
>>
>> MOD_PYTHON ERROR
>>
>> ProcessId:      24982
>> Interpreter:    'carconsumption.s0'
>>
>> URI:            '/'
>> Location:       None
>> Directory:      None
>
> The '~/' prefix will be replaced with the value of 'Directory' as  
> shown here, but it
> isn't set because you have the PythonHandler directive outside of  
> any Directory
> directive or .htaccess file. Thus, it can't know what the handler  
> root is. Using:
>
>    DocumentRoot /var/www/html/carconsumption.com
>    <Directory /var/www/html/carconsumption.com>
>    SetHandler mod_python
>    PythonHandler mod_python.publisher
>    PythonDebug On
>    PythonOption mod_python.importer.path "['~/mod']"
>    </Directory>
>
> should work, as will:
>
>    DocumentRoot /var/www/html/carconsumption.com
>    SetHandler mod_python
>    PythonHandler mod_python.publisher
>    PythonDebug On
>    PythonOption mod_python.importer.path "['/var/www/html/ 
> carconsumption.com/mod']"
>
> Note, when inside a Location directive, '~/' will not work either  
> as Location isn't
> associated with a directory.
>
> What I have to think about now is whether when both Directory and  
> Location
> directives aren't being used, that '~/' maps to DocumentRoot. I  
> never thought
> about this particular scenario.

If you get the latest version of source code for 3.3 from subversion  
repository, it
should now work without having to have the handler directive inside  
the context
of the Directory directive.

The code will now always have the handler root fallback to being the  
document
root if used in VirtualHost container or in main server context. It  
will also fallback
to using the document root if used in a Location directive as well.

Graham


More information about the Mod_python mailing list