urllib2

Clarence Gardner clarence at netlojix.net
Fri Aug 8 02:34:12 CEST 2003


On Thu, 07 Aug 2003 16:00:17 +0000, Clarence Gardner wrote:

> I must not be getting the point of this from the documentation.
> I want to connect to a URL and see what it redirects to. I built
> a redirect handler that does nothing much (for testing) and installed
> it thusly:
>   import urllib2
> 
>   class R(urllib2.HTTPRedirectHandler):
>       def redirect_request(req,fp,code,msg,hdrs):
>               print "%s, %s, %s, %s, %s" % (req,fp,code,msg,hdrs)
>               raise urllib2.HTTPError
> 
>   o = urllib2.build_opener(R())
>   urllib2.install_opener(o)
>   f = urllib2.urlopen('http://sony.com/walkmanreg')
>   print f.read()[:200]
> 
> but instead of printing the message from my redirect handler, it prints
> out the text of the redirected-to URL.
> 
> Any help appreciated.
> clarence at silcom.com

Things changed amazingly upon upgrading to Python2.3
Sorry.





More information about the Python-list mailing list