Senthil Kumaran <[email protected]> added the comment:
Hi Jason & Petri,
urllib2.HTTPError never had a reason attribute. In the docs, it is mentioned
that only URLError has the reason attribute. The HTTPError sublasses URLError
and addinforurl class, but the further initialization happens only in the
addinforurl class atrs.
If you got confused that the HTTPError as args and not reason, the 'args' is
not coming from URLError.
HTTPError is raised for peculiar conditions such like authentication failures
and it is 'used' as expected failure for certain authentication conditions.
URLError is not so, it is seen more as an exception like socket errors.
The example your illustrated is an Authentication failure and as per docs, it
is guaranteed to have code attribute to verify the kind of HTTP error are
getting. msg is corresponding HTTP error code msg.
Take this example for URLError which will have reason attribute, it will work
in both 2.7,3.2 and 3.3
import urllib.request, urllib.error, urllib.parse
try:
urllib.request.urlopen('http://aninvalidsite/something')
except urllib.error.URLError as exc:
print(exc.reason)
Because this is a socket error, the reason as "[Errno -2] Name or service not
known" and HTTPError may not be a proper exception for this.
This is more of an IOError which urllib calls a URLError.
I am not sure, how the need for 'reason' attribute for HTTPError exception was
felt as the docs just say about 'code'. (HTTPError is informed as a subclass
of URLError, but HTTPError does not call the URLError 's __init__ and acts
standalone.
I am not sure, how to go about with this bug. If a new .reason attribute has to
be added to HTTPError, then it is a feature request though, I wonder why we
need when code and msg serve an adequate purpose.
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue13211>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com