Error when display socekt content

Peter Hansen peter at engcorp.com
Sat Feb 19 20:42:04 EST 2005


myzhang at gmail.com wrote:
> The displayed string looks like some wierd chars (unreadable to human
> being at all), when I tried to display the received message by socket.
> I read by this line:
>   body = self.io.blockingRead (int(header.getFieldCN
> ('Content-Length')))
>   print "socket content: " + body
> 
> I am new to python, could you tell me where I did wrong?

You didn't post enough information for anyone to help much, that's
what...

Most importantly, what did you *expect* the above to do?  For
all I can tell, you should have expected it to print
"socket content: " followed by some potentially unreadable
data, which is what you got...

Also, it will help if you describe what "self.io" is, what
"header.getFieldCN" is, and what kind of communications protocol
is involved in what you're doing.  And, if it's HTTP as it
appears it might be, perhaps explain why you aren't using
something simple like urllib2 to deal with it...

Mentioning what platform (versions of OS and Python) you
are using is always a good idea too.

Cutting and pasting the *actual* output, or something
that describes a little better what you actually got and
what you expected to get is also a good idea... give us
enough information to help you and you'll be helping yourself.

-Peter



More information about the Python-list mailing list