Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #7952

Re: HTTPConncetion - HEAD request

From "Elias Fotinis" <efotinis@yahoo.com>
Subject Re: HTTPConncetion - HEAD request
Date 2011-06-19 16:21 +0300
References <b06bf827-671c-4555-b3ec-108bc5c3a0b8@m10g2000yqd.googlegroups.com> <mailman.69.1308304747.1164.python-list@python.org> <38df1fae-a7bd-43c3-8b3d-b8d685af4b9f@fp11g2000vbb.googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.145.1308489706.1164.python-list@python.org> (permalink)

Show all headers | View raw


On Fri, 17 Jun 2011 20:53:39 +0300, gervaz <gervaz@gmail.com> wrote:

> 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...

Use c.getcode() to get the response code. When you're testing interactively, you might find printing the headers with "print c.headers" quite handy.

Don't forget to close the response (c.close()) when your script exits its experimental state.

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


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