[mod_python] ImportError issue

Reuben A Christie christie at knewco.com
Fri Dec 5 22:31:12 EST 2008


its version 3.3.1 i removed send_http_header() call, still n o difference

Graham Dumpleton wrote:
> 2008/12/6 Reuben A Christie <christie at knewco.com>:
>   
>> this is how my apache config looks like
>> <Directory /usr/local/apache/htdocs/linker_python >
>>       Options  ExecCGI -MultiViews FollowSymLinks
>>       AllowOverride All
>>       Order allow,deny
>>       allow from all
>>       AddHandler mod_python .py
>>       PythonHandler launch
>>       PythonDebug On
>>       AddType text/plain
>> </Directory>
>>
>> and in the code i do following
>>
>> req.send_http_header()
>> req.content_type = 'text/xml' (it does not matter what do i set content
>> type, even if i change this to text/plain or text/html does not make any
>> differece)
>> req.write("<response>hello world</response>")
>>     
>
> Which version of mod_python are you using?
>
> Calling req.send_http_header() is only needed for mod_python 2.7.X and
> older. Even then, it should go after setting req.content_type.
>
> If still using mod_python 2.7.X, then upgrade. If you can't because
> you are using Apache 1.3, then consider using mod_wsgi instead and
> write your web application to WSGI API, using one of the many
> toolkits/frameworks out there for WSGI.
>
> Graham
>
>   
>> Graham Dumpleton wrote:
>>     
>>> 2008/12/6 Reuben A Christie <christie at knewco.com>:
>>>
>>>       
>>>> In the python script itself, i set the content type to text/plain , I
>>>> have
>>>> not set any AddType directive in apache config
>>>>
>>>>         
>>> Please post code snippet showing how this is being done and what
>>> handler you are using? Ie., custom handler, mod_python.publisher etc.
>>>
>>> What AddHandler directives do you have set in Apache configuration?
>>>
>>> Have you setup any output filters in Apache, ie., AddOutputFilter*
>>> directives?
>>>
>>> Graham
>>>
>>>
>>>       
>>>> Graham Dumpleton wrote:
>>>>
>>>>         
>>>>> 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
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>             
>>>>>           
>>>> _______________________________________________
>>>> Mod_python mailing list
>>>> Mod_python at modpython.org
>>>> http://mailman.modpython.org/mailman/listinfo/mod_python
>>>>
>>>>
>>>>
>>>>         
>>>
>>>       
>> _______________________________________________
>> Mod_python mailing list
>> Mod_python at modpython.org
>> http://mailman.modpython.org/mailman/listinfo/mod_python
>>
>>
>>     
>
>
>   
-------------- 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/20081205/06a4ca9a/smime.bin


More information about the Mod_python mailing list