[issue11280] urllib2 http_error_302 calls undefined "getheaders" method
Andres Riancho
report at bugs.python.org
Tue Feb 22 03:22:29 CET 2011
New submission from Andres Riancho <andres.riancho at gmail.com>:
Buggy Code:
"""
def http_error_302(self, req, fp, code, msg, headers):
# Some servers (incorrectly) return multiple Location headers
# (so probably same goes for URI). Use first header.
if 'location' in headers:
newurl = headers.getheaders('location')[0]
elif 'uri' in headers:
newurl = headers.getheaders('uri')[0]
else:
return
"""
The getheaders method is not be defined for the headers parameter, which is a dict object. This seems to be a mistake with the HTTPResponse. getheaders function that's defined in httplib.py
Fixed Code:
"""
def http_error_302(self, req, fp, code, msg, headers):
# Some servers (incorrectly) return multiple Location headers
# (so probably same goes for URI). Use first header.
if 'location' in headers:
newurl = headers.get('location')
elif 'uri' in headers:
newurl = headers.get('uri')
else:
return
"""
----------
components: Extension Modules
messages: 129026
nosy: Andres.Riancho
priority: normal
severity: normal
status: open
title: urllib2 http_error_302 calls undefined "getheaders" method
type: crash
versions: Python 2.6
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue11280>
_______________________________________
More information about the Python-bugs-list
mailing list