[Web-SIG] Making HEAD request using urllib2 module

Lloyd Kvam pythonTutor at venix.com
Tue Sep 7 14:50:00 CEST 2004


Thanks for the response.

On Mon, 2004-09-06 at 17:44, John J Lee wrote:
> On Mon, 6 Sep 2004, Lloyd Kvam wrote:
> 
> > I wrote a URL checker to verify that a website is up and responding.
> > For this, a HEAD request rather than GET seems better.  The urllib2
> > module provides a Request class with a get_method method.  I derived my
> > HeadRequest class overriding get_method to return HEAD if there was no
> > POST data.  Then I discovered that AbstractHTTPHandler.do_open did not
> > use Request.get_method, but simply used GET if there was no POST data.
> >
> > I changed do_open to use Request.get_method and that's working for me.
> > Should I be reporting a bug and offering a patch?  Or am I missing the
> > boat on other issues?
> 
> Don't think it's a bug -- it's simply not implemented.  But do go ahead
> and upload it as a patch to the SF patch tracker!
> 
> I don't like the idea of a subclass just for HEAD requests (but then I
> don't much like the Request class at all).  How about an additional
> optional arg to the Request constructor, named 'method', instead?

I started down the subclass path on the assumption that overriding
get_method was all that was necessary and I could avoid changing the
urllib2 module.

> 
> 
> > Is anyone making changes to urllib2?
> 
> Yes, me.
> 
> 
> John
> _______________________________________________
> Web-SIG mailing list
> Web-SIG at python.org
> Web SIG: http://www.python.org/sigs/web-sig
> Unsubscribe: http://mail.python.org/mailman/options/web-sig/pythontutor%40venix.com
-- 
Lloyd Kvam
Venix Corp



More information about the Web-SIG mailing list