On 17 Giu, 01:00, Ian Kelly <ian.g.ke...@gmail.com> wrote: > On Thu, Jun 16, 2011 at 4:43 PM, gervaz <ger...@gmail.com> wrote: > > Hi all, can someone tell me why the read() function in the following > > py3 code returns b''? > > >>>> h = http.client.HTTPConnection("www.twitter.com") > >>>> h.connect() > >>>> h.request("HEAD", "/", "HTTP 1.0") > >>>> r = h.getresponse() > >>>> r.read() > > b'' > > You mean why does it return an empty byte sequence? Because the HEAD > method only requests the response headers, not the body, so the body > is empty. If you want to see the response body, use GET. > > Cheers, > Ian
The fact is that I have a list of urls and I wanted to retrieve the minimum necessary information in order to understand if the link is a valid html page or e.g. a picture or something else. As far as I understood here http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html the HEAD command is the one that let you do this. But it seems it doesn't work. Any help? Mattia -- http://mail.python.org/mailman/listinfo/python-list