HTTPResponse.read() returns an empty string?

Christoph Söllner christoph.soellner at web.de
Tue Oct 18 07:27:54 EDT 2005


ok got it:
One cannot close the connection before reading the answer.
Seems that in my original source the new assigned variable
'answ' is destroyed or emptied with the connection.close()
command; very strange behaviour.
> """
> import httplib
> conn = httplib.HTTPConnection('www.python.org');
> conn.request("GET", "/index.html");
> answ = conn.getresponse();
> print answ.status, answ.reason
>>>> 200 OK
> conn.close();
> print "Start";
>>>> Start
> print answ.read();
>>>>
> print len(answ.read());
>>>> 0





More information about the Python-list mailing list