httplib module

B

Boris Ozegovic

Why do I get double new lines when geting data from server? Example:

I have a following file:
------start-------------
<html>
<body>
Ovo je testni primjerak
</body>
</html>
------end---------------

And the code is:
conn = httplib.HTTPConnection("localhost:8000")
conn.request("GET", "/folder/index.html")
response = conn.getresponse()
reply = response.read()

print reply
<html>\n\n<body>\n\nOvo je testni primjerak\n\n</body>\n\n</html>\n\n
 
S

Steve Holden

Boris said:
How? It's customary to include details when you've solved your own
problem in case someone else gets the same issue.

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------
 
B

Boris Ozegovic

Steve said:
How? It's customary to include details when you've solved your own
problem in case someone else gets the same issue.

Ok. In do_GET I had this two lines:

for line in file:
print line

As you can see, print inserted another \n. :)

Correct code is:

for line in file:
print line,
 
S

Steve Holden

Boris said:
Ok. In do_GET I had this two lines:

for line in file:
print line

As you can see, print inserted another \n. :)

Correct code is:

for line in file:
print line,
Thanks. Glad you got it sorted out.

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
--------------- Asciimercial ------------------
Get on the web: Blog, lens and tag the Internet
Many services currently offer free registration
----------- Thank You for Reading -------------
 
D

Dennis Lee Bieber

Ok. In do_GET I had this two lines:

for line in file:
print line

As you can see, print inserted another \n. :)

Correct code is:

for line in file:
print line,

Lots of choices... one of which is to not use the convenience
statement "print xxx", but to use sys.stdout.write(xxx). Second would be
to strip leading/trailing whitespace from the line read in... "print
xxx.strip()"
--
Wulfraed Dennis Lee Bieber KD6MOG
(e-mail address removed) (e-mail address removed)
HTTP://wlfraed.home.netcom.com/
(Bestiaria Support Staff: (e-mail address removed))
HTTP://www.bestiaria.com/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top