BrownFox97
BrownFox97

Reputation: 393

Python String with HTML /

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

Upvotes: 1

Views: 899

Answers (2)

John La Rooy
John La Rooy

Reputation: 304413

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

Upvotes: 0

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799240

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

Upvotes: 1

Related Questions