[mod_python] zero terminated strings and req.write

Erik Stephens mod_python at 24ksoftware.com
Mon Mar 8 14:35:04 EST 2004


On Mon, 8 Mar 2004, Frederick Grim wrote:

> def gen_xml():
> 	return """<?xml ... Tons of xhtml stuff here
>
> </html>"""
>
> def main(req, ERR='0'):
> 	re.content_type = 'text/xml'
> 	req.write(gen_xml())
> 	return apache.OK
>
> The problem here is that python puts null bytes at the end of a
> string and req.write fails with the error that there is a 0 after
> </html>.

How does it fail?  Raises an exception?  What is the actual exception
type and value?  It sounds strange to me cuz I've never had to worry
about null bytes in strings in my Python travels.


> How do I get this failure to not happen.  Even if i set content_type
> to 'text/html' there appears a little zero at the end of my
> script. It seems like a bug? maybe.  I am using mod_python 3.1.3
> apache 2.0.47, and python 2.3

Dumb questions maybe, but what handler are you using?  If you're using
the publisher handler, then maybe that zero at the end is what
apache.OK equals?


Best regards,
Erik



More information about the Mod_python mailing list