[mod_python] multipart/x-mixed-replace

Graham Dumpleton grahamd at dscpl.com.au
Thu Nov 10 20:55:33 EST 2005


You can't set req.content_type in the middle of output like that.
Use:

import time

def index(req):
  req.content_type="multipart/x-mixed-replace;boundary=test"
  req.write("--test\n")
  for i in range(5):
    req.write("Content-Type: text/plain\n")
    req.write("\n")
    req.write("Hello Browser %d\n"%i)
    req.write("--test\n")
    time.sleep(1)
  return "\n"


Note that not all browser support this form of server push. Only
Netscape derived browsers may do so. IE didn't used to and I can't
get Safari to understand it either.

Graham

Bjorn Sundberg wrote ..
> Hello. I am a newcomer to both mod_python and python.
> I am trying to get the multipart/x-mixed-replace to work with mod_python.
> But when i am running it it will not display any text in my firefox browser.
> But when looking in the "display page source" i can see the text.
> 
> Do you out there know what i am doing wrong?
> 
> Regards Björn.
> 
> ----Code---
> #!/usr/bin/env python
> import time
> from mod_python import psp
> 
> def index(req):
> req.content_type='multipart/x-mixed-replace;boundary=test'
> req.write("---test\n")
> for i in range(5):
> req.content_type='text/plain'
> req.write("Hello Browser")
> req.write("\n--test\n")
> time.sleep(1)
> ---End---


More information about the Mod_python mailing list