[mod_python] ImportError issue

Reuben A Christie christie at knewco.com
Thu Dec 4 10:37:57 EST 2008


thanks alot graham. I was able to import the modules the way you showed. 
its little intriguing but I think I ll find a better way by combining 
them into one __init__.py  hopefully that will work
one more question, I keep seeing this warning message on apache log
[warn] Cannot get media type from 'mod_python'
its not causing any issue but I really don't understand why is it appearing


Graham Dumpleton wrote:
> 2008/12/3 Reuben A Christie <christie at knewco.com>:
>   
>> Hi all, I am pretty novice user of mod_python. and there is an issue that I
>> am experiencing with mod_python scripts for past 2 days that I am not able
>> to solve.
>>
>> my directory structure is as following,
>>
>> DocumentRoot :  /usr/local/apache2/htdocs/
>> i have a directory structure for mod_python scripts under DocumentRoot is,
>>
>> launch.py
>> python_test/p1/test1
>> python_test/p2/test2
>>
>> in apache config, i have added following
>>
>> <Directory /usr/local/apache/htdocs/python_test >
>>       AllowOverride All
>>       Order allow,deny
>>       allow from all             AddHandler mod_python .py
>>       PythonHandler launch
>>       PythonDebug On
>> </Directory>
>>
>> and launch.py looks like this,
>>
>> import os.path
>> from mod_python import apache, Session, util
>>
>> def handler(req):
>>       request = os.path.splitext(os.path.basename( req.uri ))[0]
>>       req.content_type = 'text/plain'
>>       req.send_http_header()
>>
>>       status = apache.OK
>>       if request != None:
>>               mod = __import__(request)
>>     
>
> This is the wrong way of going about it. See below.
>
>   
>>               if request == "test1":
>>                       status = mod.handler(req)
>>        return status
>>            basically this script should act as gateway for rest of the
>> python scripts .
>>
>> when I test it with, http://localhost/python_test/test1.py it does not work
>> (i get Not found message) and if I do http://localhost/python_test/p1 i get
>> the source code of the script appear.
>>     
>
> For configuration as written, the launch.py file is in wrong location.
>
> First off suggest that launch.py not be in htdocs as then someone can
> download source code to your handler.
>
> Presuming you are using mod_python 3.3.1 (if not then upgrade), move
> the launch.py file elsewhere and then change configuration to use:
>
>   PythonHandler /some/path/launch.py
>
> Where path is location of launch.py outside of htdocs.
>
> Also don't use __import__. You are better off using import_module()
> from mod_python. That way you can just supply a path to file to import
> and not have to worry about PythonPath and lots of other module
> madness. See:
>
>   http://www.modpython.org/live/current/doc-html/pyapi-apmeth.html
>
> Graham
>
>
>   
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3316 bytes
Desc: S/MIME Cryptographic Signature
Url : http://mm_cfg_has_not_been_edited_to_set_host_domains/pipermail/mod_python/attachments/20081204/b4244260/smime.bin


More information about the Mod_python mailing list