urllib2: handle an error (302)

Antoni Villalonga frikimaster at gmail.com
Tue Sep 11 15:16:04 EDT 2007


2007/9/11, O.R.Senthil Kumaran:
> > 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

Tnks It works!!

-- 
"Boring two-person multiplayer may turn friends into enemies."

Antoni Villalonga i Noceras
#Bloc# ~> http://friki.CAT
#Jabber# ~> friki at bulmalug.net



More information about the Python-list mailing list