HTTP response code

Carlos Ribeiro carribeiro at gmail.com
Sat Dec 4 12:53:35 EST 2004


On Fri, 3 Dec 2004 17:28:43 -0200, Jonas Galvez <jonasgalvez at gmail.com> 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:

http://mail.python.org/pipermail/web-sig/2004-September/000814.html

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
blog: http://rascunhosrotos.blogspot.com
blog: http://pythonnotes.blogspot.com
mail: carribeiro at gmail.com
mail: carribeiro at yahoo.com



More information about the Python-list mailing list