urllib2

  • Thread starter Clarence Gardner
  • Start date
C

Clarence Gardner

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.
(e-mail address removed)
 
C

Clarence Gardner

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.
(e-mail address removed)

Things changed amazingly upon upgrading to Python2.3
Sorry.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top