Response codes and \r\n
__peter__ at web.de
Thu Mar 5 11:54:04 CET 2009
Catherine Heathcote wrote:
> I am reading an XML file (code at the end if it helps) and all goes well
> except I am getting the http response code printed. So everything (hat
> works of course) has "200 OK" on the first line. Am I missing some
> simple way of surprising this, or should I just delete the 1st line
> before playing with the content?
Just remove the line
Whoever wrote that script *wanted* it to print that "200 OK"
> Also everything I get has "\r\n" in it, which atm I am getting rid of
> with strip(), is that the best way?
That is because you are getting back bytes, not a string. You can convert
the data with
data = data.decode("utf-8") # or whatever the actual encoding is
and then mess around with string methods or regular expressions, but if you
want to do it right you have to learn about element tree
or one of the alternatives.
Also note that conn.close will *not* call the close method. It should be
More information about the Python-list