classification
Title: AttributeError from HTTPError when using digest auth
Type: crash Stage:
Components: Library (Lib) Versions: Python 3.4, Python 3.3, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: orsenthil Nosy List: berker.peksag, orsenthil, python-dev, scjody
Priority: normal Keywords: patch

Created on 2012-08-16 20:35 by scjody, last changed 2014-03-13 16:01 by python-dev. This issue is now closed.

Files
File name Uploaded Description Edit
reproducer.py scjody, 2012-08-16 20:35 reproducer
issue15701.diff berker.peksag, 2012-12-07 12:30 review
Issue1571.patch orsenthil, 2012-12-10 09:35
Messages (8)
msg168407 - (view) Author: Jody McIntyre (scjody) Date: 2012-08-16 20:35
I attempted to connect to a site using urllib2 and digest authentication and it raised an HTTPError (due to an incorrect username and password, which is expected).  I attempted to run the info() method of the HTTPError to get more information, but it failed with an AttributeError (this is the bug).

$ ./reproducer.py 
Traceback (most recent call last):
  File "./reproducer.py", line 16, in <module>
    print e.info()
  File "/usr/lib/python2.6/urllib.py", line 987, in info
    return self.headers
AttributeError: 'HTTPError' object has no attribute 'headers'

$ python --version
Python 2.6.6
msg169511 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2012-08-31 09:13
Python 2.6 is now in security-fix-only mode.
msg169560 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2012-08-31 16:49
Okay, this is funny. first info is invoking addinfourl of urllib, which would return headers. But in urllib2, the headers are self.hdrs

I would side with the documentation that info is advertised method for HTTPError object. In 2.7,  I guess just docs could be improved. This problem would be the present in 3.x.
msg177270 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2012-12-10 09:35
Even though 2.x is in security fix mode, this can be fixed by a overriding the base class's info method in the HTTPError class and returning the .hdrs attribute instead of .headers.
msg177271 - (view) Author: Roundup Robot (python-dev) Date: 2012-12-10 10:09
New changeset ad1c1164f68b by Senthil Kumaran in branch 'default':
Fix Issue15701 : add .headers attribute to urllib.error.HTTPError
http://hg.python.org/cpython/rev/ad1c1164f68b
msg177998 - (view) Author: Roundup Robot (python-dev) Date: 2012-12-23 17:13
New changeset 3046bfea59f3 by Senthil Kumaran in branch '2.7':
Fix Issue15701 - HTTPError info method call raises AttributeError. Fix that to return headers correctly
http://hg.python.org/cpython/rev/3046bfea59f3

New changeset 919ebf74bfdb by Senthil Kumaran in branch '3.2':
Fix Issue15701 - HTTPError info method call raises AttributeError. Fix that to return headers correctly
http://hg.python.org/cpython/rev/919ebf74bfdb

New changeset a15109398294 by Senthil Kumaran in branch '3.3':
merge from 3.2
http://hg.python.org/cpython/rev/a15109398294
msg177999 - (view) Author: Senthil Kumaran (orsenthil) * (Python committer) Date: 2012-12-23 17:14
Okay. this is fixed in all versions of python. Sorry for the delay.
msg213410 - (view) Author: Roundup Robot (python-dev) Date: 2014-03-13 16:01
New changeset 361c10d06b9c by R David Murray in branch 'default':
whatsnew: HTTPError.headers (#15701).
http://hg.python.org/cpython/rev/361c10d06b9c
History
Date User Action Args
2014-03-13 16:01:10python-devsetmessages: + msg213410
2012-12-23 17:14:40orsenthilsetstatus: open -> closed
resolution: fixed
messages: + msg177999
2012-12-23 17:13:57python-devsetmessages: + msg177998
2012-12-10 10:09:47python-devsetnosy: + python-dev
messages: + msg177271
2012-12-10 09:35:36orsenthilsetfiles: + Issue1571.patch

messages: + msg177270
2012-12-07 12:30:36berker.peksagsetfiles: + issue15701.diff
keywords: + patch
versions: + Python 3.3, Python 3.4
2012-08-31 16:49:35orsenthilsetassignee: orsenthil

messages: + msg169560
nosy: + orsenthil
2012-08-31 09:13:29berker.peksagsetversions: + Python 2.7, - Python 2.6
nosy: + berker.peksag

messages: + msg169511

components: + Library (Lib)
2012-08-16 20:35:57scjodycreate