[mod_python] Re: req.write() in publisher_handler

vio vmilitaru at sympatico.ca
Fri Aug 16 18:17:27 EST 2002


Try it like this:

import mod_python.apache
#from mod_python import apache
pageA = """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head><title>Test page</title></head>
<body>  Page A <br>"""
pageB = "Page B</body> </html>"

def req_write(REQUEST):
  REQUEST.status = mod_python.apache.OK
  REQUEST.content_type = "text/html; charset=utf-8"
  REQUEST.send_http_header()
  REQUEST.write(pageA)
  REQUEST.write(pageB)
  raise mod_python.apache.SERVER_RETURN, mod_python.apache.OK

As you can see, we do multiple writes to the browser.
I tested it on my snake, and it works as advertised.
Vio

* Mateusz Korniak <mateusz at ant.gliwice.pl> [020816 17:31]:
> On Friday 16 August 2002 22:58, vio wrote:
> > * Mateusz Korniak <mateusz at ant.gliwice.pl> [020816 15:26]:
> > > Yes. But what in publisher handler case ?
> > > Can you use req.write() instead of returning page ?
> > > I get Internal server error in that case ... :(
> >
> > I don't quite understand your question. req.write() IS the returning page.
> > But I think I know where the bobo is: it's the Internal server error
> > message.
> 
> So let me be ( I hope) much more clear: Below my publisher handler:
> 
> import mod_python.apache
> page = """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
> <html><head><title>Test page</title></head>
> <body> Test </body> </html>"""
> 
> def req_write(req):
> 	req.status = mod_python.apache.OK
> 	req.content_type = "text/html; charset=utf-8"
> 	req.send_http_header()
> 	req.write(page)
> 	open("/tmp/marker","w") # Test if we have exceptions 
> 		#before returning from handler
> 
> def req_return(req):
> 	req.status = mod_python.apache.OK
> 	req.content_type = "text/html; charset=utf-8"
> 	req.send_http_header()
> 	return page
> 
> http://abbon.ant.vpn/test.py/req_return - returns what expected
> while 
> http://abbon.ant.vpn/test.py/req_write returns more some additional data 
> (reaching marker):
> 
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
> <html><head><title>Test page</title></head>
> <body> Test </body> </html>HTTP/1.1 500 Internal Server Error
> Date: Fri, 16 Aug 2002 21:11:31 GMT
> Server: Apache/1.3.26 (Unix)  (PLD/Linux) mod_python/2.7.8 Python/2.2.1
> Transfer-Encoding: chunked
> Content-Type: text/html; charset=iso-8859-1
> 
> <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
> <HTML><HEAD>
> <TITLE>500 Internal Server Error</TITLE>
> </HEAD><BODY>
> <H1>Internal Server Error</H1>
> The server encountered an internal error or
> misconfiguration and was unable to complete
> your request.<P>
> Please contact the server administrator,
>  matkor at ant.gliwice.pl and inform them of the time the error occurred,
> and anything you might have done that may have
> caused the error.<P>
> More information about this error may be available
> in the server error log.<P>
> <P>Additionally, a 500 Internal Server Error
> error was encountered while trying to use an ErrorDocument to handle the 
> request.
> <HR>
> <ADDRESS>Apache/1.3.26 Server at <A 
> HREF="mailto:matkor at ant.gliwice.pl">abbon.ant.vpn</A> Port 80</ADDRESS>
> </BODY></HTML>
> 
> 
> As far I understand publisher both results should be the same ...
> Perhaps my mod_python /apache are broken ?
> 
> -- 
> Mateusz Korniak
> 



More information about the Mod_python mailing list