[mod_python] Questions for the FAQ - please check and confirm (req.write() and return) also docs update ...

Fabian Fagerholm fabbe at paniq.net
Mon Aug 19 11:53:01 EST 2002


On Fri, 2002-08-16 at 16:00, Gregory (Grisha) Trubetskoy wrote:
> On 16 Aug 2002, Fabian Fagerholm wrote:
> > If you're using the Publisher handler, you can use req.write() once,
> > but then you *have* to return something at the end of your function,
> > or things won't work.
> 
> You should be able to use write() many times as you like. It should also
> be ok to return an empty string *if* you have written something with
> write(), otherwise returning an empty document will cause a problem with
> Netscape at least.

Right, now I have it working. I see now why I was confused. It seems to
me that mod_python is behaving differently at different times. For
example:

If I follow the Tutorial section in the mod_python docs, and create a
directory /home/fabbe/public_html/mod_python/temp_test_1 for my tests,
and in this directory, I place a .htaccess file with the following
contents:

    AddHandler python-program .py
    PythonHandler myscript

just like in the tutorial. Then, I write myscript.py in the same
directory:

    from mod_python import apache
    
    def handler(req):
        req.content_type = "text/plain"
        req.send_http_header()
        req.write("Hello, World!")
    
        return apache.OK
    
I then load ~fabbe/mod_python/temp_test_1/myscript.py from the web
server, and I get the following:

    Hello, World!
    <p>/home/fabbe/public_html/mod_python/temp_test_1/myscript.py</p>
    
which is not what I expected. But when I press reload on my browser, the
last line disappears and everything works as expected *even if I remove
those files and rewrite them, or change 'myscript' to 'fooscript'*!

I don't get it... :)

The apache logs show the following:

First access:
    212.226.163.85 - - [19/Aug/2002:11:34:33 +0300]
     "GET /~fabbe/mod_python/temp_test_1/myscript.py HTTP/1.1" 200 99
     "https://no.paniq.net/~fabbe/mod_python/temp_test_1/" "Mozilla/5.0
     Galeon/1.2.5 (X11; Linux i686; U;) Gecko/20020610 Debian/1.2.5-1"

Subsequent accesses:
    212.226.163.85 - - [19/Aug/2002:11:41:52 +0300]
     "GET /~fabbe/mod_python/temp_test_1/myscript.py HTTP/1.1" 200 25
     "-"
     "Mozilla/5.0 Galeon/1.2.5 (X11; Linux i686; U;) Gecko/20020610
     Debian/1.2.5-1"

The only difference I see compared to the tutorial is that I'm using
https. But that shouldn't affect mod_python, should it?

Could someone clarify?

Cheers,
Fabian





More information about the Mod_python mailing list