From: Gnarlodious on
Wit's end on this. I have a script outputting a stream with:
sys.stdout.buffer.write(("""\n<?xml version='1.0' encoding='utf-8'?>

The script works normally in 2 browsers, but in Firefox all I see is
source code.

Also, running the script in iPhone from my server shows the same
source code. Which is a little strange since iPhone and Safari both
use Webkit. This occurs also on my home dev server.

I attempted to validate the output but all I get is error:


Sorry, I am unable to validate this document because its content type
is text/plain, which is not currently supported by this service.
The Content-Type header is sent by your web server (or web browser if
you use the file upload interface) and depends on its configuration.
Commonly, web servers will have a mapping of filename extensions (such
as ".html") to MIME Content-Type values (such as text/html).
That you received this message can mean that your server is not
configured correctly, that your file does not have the correct
filename extension, or that you are attempting to validate a file type
that we do not support yet.


Is the output stream not recognized because of the
sys.stdout.buffer.write statement?

This is a Python3 script ending with .py. Server is Apache 2. Hope
someone can explain.

-- Gnarlie
From: Gnarlodious on
Thanks for that, for some reason I assumed sys.stdout.buffer.write
sent the http header but I was wrong.

Even so, Firefox still refused to render prperly, but this works/:

content-type: application/xhtml+xml; charset=utf-8\n\n

-- Gnarlie
From: MRAB on
Gnarlodious wrote:
> Thanks for that, for some reason I assumed sys.stdout.buffer.write
> sent the http header but I was wrong.
>
> Even so, Firefox still refused to render prperly, but this works/:
>
> content-type: application/xhtml+xml; charset=utf-8\n\n
>
Perhaps it's not so much that there's a problem with Firefox but that
the other browsers are guessing what the content type should be if it's
missing. (Refusing to guess is a Pythonic trait. :-))