urllib2

Discussion in 'Python' started by Clarence Gardner, Aug 8, 2003.

  1. 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 Gardner, Aug 8, 2003
    #1
    1. Advertising

  2. 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.
    >


    Things changed amazingly upon upgrading to Python2.3
    Sorry.
    Clarence Gardner, Aug 8, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kylotan

    urllib2 for HTTPS/SSL

    Kylotan, Jul 8, 2003, in forum: Python
    Replies:
    5
    Views:
    553
    Jeremy Hylton
    Jul 9, 2003
  2. John J. Lee

    Re: urllib2 http status

    John J. Lee, Jul 29, 2003, in forum: Python
    Replies:
    1
    Views:
    2,474
    rosendo
    Jul 31, 2003
  3. O. Koch

    FTP with urllib2 behind a proxy

    O. Koch, Aug 7, 2003, in forum: Python
    Replies:
    4
    Views:
    1,273
    John J. Lee
    Aug 14, 2003
  4. Joseph

    urllib2/httplib and email mime

    Joseph, Aug 22, 2003, in forum: Python
    Replies:
    0
    Views:
    302
    Joseph
    Aug 22, 2003
  5. Josef Cihal
    Replies:
    0
    Views:
    727
    Josef Cihal
    Sep 5, 2005
Loading...

Share This Page