urllib2

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Clarence Gardner

    urllib2

    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.HTTPR edirectHandler) :
    def redirect_reques t(req,fp,code,m sg,hdrs):
    print "%s, %s, %s, %s, %s" % (req,fp,code,ms g,hdrs)
    raise urllib2.HTTPErr or

    o = urllib2.build_o pener(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@silcom .com

  • Clarence Gardner

    #2
    Re: urllib2

    On Thu, 07 Aug 2003 16:00:17 +0000, Clarence Gardner wrote:
    [color=blue]
    > 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.HTTPR edirectHandler) :
    > def redirect_reques t(req,fp,code,m sg,hdrs):
    > print "%s, %s, %s, %s, %s" % (req,fp,code,ms g,hdrs)
    > raise urllib2.HTTPErr or
    >
    > o = urllib2.build_o pener(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@silcom .com[/color]

    Things changed amazingly upon upgrading to Python2.3
    Sorry.

    Comment

    Working...