HTTPResponse.read() returns an empty string?

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Wed Oct 19 00:10:14 CEST 2005


In <dj2m7k$s7n$1 at wsc10.lrz-muenchen.de>, Christoph Söllner wrote:

> ok got it:
> One cannot close the connection before reading the answer.

Yep, because the "answer" is read over the connection.

> Seems that in my original source the new assigned variable
> 'answ' is destroyed or emptied with the connection.close()
> command; very strange behaviour.

No, it's not emptied or destroyed.  The read() method reads the content
over the connection.  That doesn't work if the connection is closed.  It's
like closing a file and then reading from it.

The response object contains just the headers.  So you can inspect them
before you decide to download the actual content.

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list