urllib2: handle an error (302)
O.R.Senthil Kumaran
orsenthil at gmail.com
Tue Sep 11 09:56:41 EDT 2007
> When urllib2 libs visit a URL with 302 error follow the location
> automatically. I need to get the location in order to get the full
> URL (not relative URL) parsing html code.
urllib2 automatically handles the 302 redirection. What you get as the end result is the 'redirected' page.
- If all you want is the 'redirected' page. Blindly use urllib2, it handles it.
- If you want a 'smarter' way of handling redirection, then you might have to extend the HTTPRedirectHandler.
A very good example is provided by Mark Pilgrim in his 'Dive Into Python'.
Have a look here:
http://www.diveintopython.org/http_web_services/index.html
Example 11.1 openanything.py
Implement your program along those lines.
Thanks,
Senthil
--
O.R.Senthil Kumaran
http://uthcode.sarovar.org
More information about the Python-list
mailing list