Indeed, it is hard to imagine what's happening. Are you using "print 'Content-type: text/html" more than once? Is it possible that some runnings of your script route through a second printing of the header? It can only happen once in a script. See my own question and the helpful replies here.