HTTP response code

Carlos Ribeiro carribeiro at
Sat Dec 4 18:53:35 CET 2004

On Fri, 3 Dec 2004 17:28:43 -0200, Jonas Galvez <jonasgalvez at> wrote:
> Hi list, here's a question about urllib. Is it possible to simply
> retrieve the HTTP responde code for a given URL? I don't want to
> download the body of the HTTP message. I simply want to check the
> response code, like, if it is 200, 301 etc. Something like:
> if urllib.urlopen(the_url).response_code == 200:
>     # ...
> Is there an easy way to do this?
> Should I be using urllib2 instead?

Jonas, check this link:

There was a discussion on the WebSig about adding support for HEAD
requests on urllib2 (they were still not implemented at that time,
three months ago). Perhaps there is a patch somewhere for it...

Carlos Ribeiro
Consultoria em Projetos
mail: carribeiro at
mail: carribeiro at

More information about the Python-list mailing list