HTTPConncetion - HEAD request

Ian Kelly ian.g.kelly at gmail.com
Thu Jun 16 19:00:57 EDT 2011


On Thu, Jun 16, 2011 at 4:43 PM, gervaz <gervaz at 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



More information about the Python-list mailing list