[mod_python] ImportError issue

Graham Dumpleton graham.dumpleton at gmail.com
Thu Dec 4 16:54:48 EST 2008


2008/12/5 Reuben A Christie <christie at knewco.com>:
> 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

What is the content type you are returning or have setup using AddType
directives? It appears it may be malformed. The message is mod_mime
complaining about it.

Graham

> 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
>>
>>
>>
>
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python
>
>


More information about the Mod_python mailing list