Newbie problem with HTTP Redirection in Python 2.4 urllib2

S

Sriram Krishnan

I've just downloaded the alpha of Python 2.4 and I'm not able to get
HTTP Redirection to work - even the examples are failing for me. They
all give the same error message (whenever a site issues a HTTP 302)

import urllib2

thing = urllib2.HTTPRedirectHandler()


opener = urllib2.build_opener(thing)


url = 'http://www.msdn.com'
page = opener.open(url)



Traceback (most recent call last):
File "test.py", line 11, in ?
f = urllib2.urlopen('http://www.msdn.com/')
File "D:\Python24\lib\urllib2.py", line 131, in urlopen
return _opener.open(url, data)
File "D:\Python24\lib\urllib2.py", line 359, in open
response = self._open(req, data)
File "D:\Python24\lib\urllib2.py", line 377, in _open
'_open', req)
File "D:\Python24\lib\urllib2.py", line 338, in _call_cha
result = func(*args)
File "D:\Python24\lib\urllib2.py", line 1014, in http_ope
return self.do_open(httplib.HTTPConnection, req)
File "D:\Python24\lib\urllib2.py", line 1008, in do_open
r.msg.dict)
File "D:\Python24\lib\urllib2.py", line 397, in error
result = self._call_chain(*args)
File "D:\Python24\lib\urllib2.py", line 338, in _call_cha
result = func(*args)
File "D:\Python24\lib\urllib2.py", line 524, in http_erro
newurl = headers.getheaders('location')[0]
AttributeError: 'dict' object has no attribute 'getheaders'



Am I making a newbie error here? Or am I missing something?

Sriram
 
J

John J. Lee

I've just downloaded the alpha of Python 2.4 and I'm not able to get
HTTP Redirection to work - even the examples are failing for me. They
all give the same error message (whenever a site issues a HTTP 302)
[...]

This is broken in 2.4a1, and was fixed in CVS on Saturday's bug day.

If you want cookie handling now, I'm pretty sure you can just grab
cookielib.py and urllib2.py from CVS and use them with 2.3.
Alternatively, use ClientCookie (cookielib is a tidied-up version of
ClientCookie):

http://wwwsearch.sf.net/ClientCookie/


HTH


John
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top