1

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

0

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

>>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.
I said "encode". You said "decode". Which one would you like to talk about?
0

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

1 Comment

@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 \\.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.