[mod_python] Mod-Python Help

Ethan Toan Ton ethanton at ethanton.com
Thu Sep 7 01:55:34 EDT 2006


Graham/David,

Thanks for the help. My packet sniffer is looking at the packets, and instead
of a new packet header, all these req.flush() calls are keeping the
connection
alive. Unfortunately, the javascript xmlhttprequest will only process the
packet once, instead of during every call to req.flush().

Is there a way to close the connection and open it again afterwards? I'm
trying to get the xmlhttprequest.onreadystatechange to process after each
call
to req.flush().

Ethan


> On 07/09/2006, at 10:39 AM, David Beal wrote:
>
>> Ethan,
>>
>>> Thanks for your help.  It turns out the problem was the "return
>>> apache.OK".  I was getting that extra 0 at the end and could not
>>> figure
>>> out why.  Thanks for the prompt replies.  I appreciate all the help.
>>>
>>
>> The problem is probably not with return apache.OK, but maybe with the
>> client's XmlHttpRequest handler not understanding chunked encoding
>> markers.  The 0 is for HTTP chunked encoding.  Look for the header:
>>
>> Transfer-Encoding: chunked
>>
>> and the first line of the content will be a hexadecimal number of the
>> content-length for the first chunk.  Each subsequent chunk comes
>> with a
>> chunk length marker.  The 0 at the end of the file indicates that
>> there
>> are no more chunks.  Chunk length markers will also appear whenever an
>> output flush occurs.
>>
>> To disable chunked encoding, you should specify a content length:
>>
>> req.headers_out['Content-Length']=str(len(code))
>
> I'd suggest it isn't anything to do with chunked encoding and the
> original
> suggestion about apache.OK is going to be correct.
>
> It is an occasional problem we have to correct whereby people who move
> from a mod_python basic handler to mod_python.publisher keep returning
> apache.OK as a status when they shouldn't with result of an extra '0'
> appearing in response.
>
> Ie., a mod_python basic handler of:
>
>    def handler(req):
>      req.content_type = 'text/plain'
>      req.write("content")
>      return apache.OK
>
> can not simply be taken and then used as mod_python.publisher
> function as:
>
>    def index(req):
>      req.content_type = 'text/plain'
>      req.write("content")
>      return apache.OK
>
> This is because mod_python.publisher will always take the result of
> the function
> and convert it to a string and append it to the response, even if
> req.write() were
> used. Thus, must be written as:
>
>    def index(req):
>      req.content_type = 'text/plain'
>      req.write("content")
>
> or for older versions of mod_python where returning None or an empty
> string is
> a problem, written as:
>
>    def index(req):
>      req.content_type = 'text/plain'
>      req.write("content")
>      return ' '
>
> Graham
>




More information about the Mod_python mailing list