Avoiding redirects with urllib

Fernando Rodriguez fernandoREMOVE_THIS at easyjob.net
Sun Jun 15 04:25:38 EDT 2008


Hello tdahsu at gmail.com,

> import urllib
> url_opener = urllib.URLopener()	# create URLopener
> #You could also work with urllib.FancyURLopener
> try:
> data = url_opener.open("http://www.somedomain.com/index.html")   #
> open index.html
> except IOError, error_code:
> if error_code[0] == "http error":
> if error_code[1] == 301:
> #do something here
> if error_code[2] == 302:
> #do something here
> I hope that's of some help!  I think you may want to delve deeper into
> FancyURLopener...


The problem is that I'm using a subclass of FancyOpener and it doesn't raise 
those exceptions.





More information about the Python-list mailing list