views:

57

answers:

2

I'm trying a simple program to send some html down a socket to a client. 2 things are goofing me up.

The code:

c.send( str.encode("<HTML><BODY>Test Page<///BODY><///HTML>") )

My python client receives:

b'<HTML><BODY>Test Page<///BODY><///HTML>'

According to Beginning Python which says it covers Python 3 (I'm using 3.1.1 on Windows), there is a String.Decode function. My environment cannot find it. I assume I'll run into the errors ('strict', 'ignore', 'replace' ) next.

Obviously, the extra /// is just guessing.

1) How do I decode this in Python?
2) I use my browser and obviously the HTML code is wrong, but I can see the server sent it. How do I make the HTML browser friendly?

Cordially,

Stephen

A: 

You want '...'.encode() and b'...'.decode(). Saying "str.encode" is shorthand for saying that all str literals have this method.

Ignacio Vazquez-Abrams
>>Saying "str.encode" is shorthand for saying that all str literals >>have this method.My environment can't find decode. Not quite sure what what you mean by all str literals have this method.
Stephen Deetz
I said "encode". You said "decode". Which one would you like to talk about?
Ignacio Vazquez-Abrams
A: 

The extra '/' is wrong. You only need to worry about escaping for '\'

gnibbler
I tried /, //, /// and then gave up there.
Stephen Deetz
@Stephen Deetz: Can you tell the difference between / and \? One needs escaping and one does not. Do not escape /. Ever. Sometimes you need to escape \ as \\.
S.Lott