Slightly off-topic... (sending HTML data through a Python socket)

Peter Hansen peter at engcorp.com
Sun Jul 29 13:22:46 EDT 2001


Adonis Vargas wrote:
> 
> I am attempting to send HTML data back to a browser which connected to X
> port. I have goen over the the HTML RFC and just can not get it to work.
> What I am attempting to do is send a redirect back to the browser. So
> far I have something as follows:
> 
> c.send("""
>           <HTML>
>           <HEAD>
>           <META HTTP-EQUIV=\"Refresh\"
> Content=0;Host=\"http://www.python.org/\">"
>           </HEAD>
>           </HTML>
>           """)

I think you should have quotation marks around the content of the 
"Content" tag, but I don't know if that would help.  You should also 
always have a <title> tag, as far as I recall, in the <head> element,
although I'm sure that wouldn't help either.

More importantly, there are many reasons why this might not work, none
of which involve the form of this part of the output.  Servers have
to send back additional information to satisfy the requirements of the
HTTP protocol, but you appear to be returning only HTML.  Check the
HTTP RFC if you have not.  Better yet, use one of the Python library
modules that already supports HTTP servers (like SimpleHTTPServer.py).

If you posted a little more context I bet you'd get an answer that 
would help more.  A more detailed description of the symptoms than
just "can not get it to work" would also help us figure it out.
(Mentioning your platform is often a good idea too, but in this case
I'm guessing Python and your problem are both platform-independent 
enough that this isn't an issue.)

Finally, have you tried *testing* this, rather than just "seeing
if it works".  In this case, the distinction would mean connecting
with something like TELNET (with the output dumped to a file for
posting here) and seeing what data is *actually* being returned from
your server, rather than just running the browser and crossing
your fingers.  If you can't figure it out by using telnet, posting
the full output here would go a long way to helping us help you.

-- 
----------------------
Peter Hansen, P.Eng.
peter at engcorp.com



More information about the Python-list mailing list