Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #7841
| From | gervaz <gervaz@gmail.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: HTTPConncetion - HEAD request |
| Date | 2011-06-17 10:53 -0700 |
| Organization | http://groups.google.com |
| Message-ID | <38df1fae-a7bd-43c3-8b3d-b8d685af4b9f@fp11g2000vbb.googlegroups.com> (permalink) |
| References | <b06bf827-671c-4555-b3ec-108bc5c3a0b8@m10g2000yqd.googlegroups.com> <mailman.69.1308304747.1164.python-list@python.org> |
On 17 Giu, 12:14, Adam Tauno Williams <awill...@whitemice.org> wrote:
> On Thu, 2011-06-16 at 15:43 -0700, gervaz 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''
>
> Because there is no body in a HEAD request. What is useful are the
> Content-Type, Content-Length, and etag headers.
>
> Is r.getcode() == 200? That indicates a successful response; you
> *always* much check the response code before interpreting the response.
>
> Also I'm pretty sure that "HTTP 1.0" is wrong.
Ok, thanks for the replies, just another question in order to have a
similar behaviour using a different approach...
I decided to implement this solution:
class HeadRequest(urllib.request.Request):
def get_method(self):
return "HEAD"
Now I download the url using:
r = HeadRequest(url, None, self.headers)
c = urllib.request.urlopen(r)
but I don't know how to retrieve the request status (e.g. 200) as in
the previous examples with a different implementation...
Any suggestion?
Thanks,
Mattia
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
HTTPConncetion - HEAD request gervaz <gervaz@gmail.com> - 2011-06-16 15:43 -0700
Re: HTTPConncetion - HEAD request Ian Kelly <ian.g.kelly@gmail.com> - 2011-06-16 17:00 -0600
Re: HTTPConncetion - HEAD request gervaz <gervaz@gmail.com> - 2011-06-17 01:19 -0700
Re: HTTPConncetion - HEAD request Chris Angelico <rosuav@gmail.com> - 2011-06-17 18:44 +1000
Re: HTTPConncetion - HEAD request Adam Tauno Williams <awilliam@whitemice.org> - 2011-06-17 06:14 -0400
Re: HTTPConncetion - HEAD request gervaz <gervaz@gmail.com> - 2011-06-17 10:53 -0700
Re: HTTPConncetion - HEAD request "Elias Fotinis" <efotinis@yahoo.com> - 2011-06-19 16:21 +0300
csiph-web