[docs] [issue13211] urllib2.HTTPError does not have 'reason' attribute.

Jason R. Coombs report at bugs.python.org
Tue Oct 18 15:06:09 CEST 2011

New submission from Jason R. Coombs <jaraco at jaraco.com>:

The urllib2 docs indicate that HTTPError is a subclass of URLError and that URLError has an attribute of 'reason', but HTTPError does not have this attribute. The docs should be updated to reflect this deviance.

It appears the Python 3.2 docs no longer include documentation for URLError

Python 2.7.2
>>> try:urllib2.urlopen('http://api.wordnik.com/v4/word.json/foo/examples')
... except urllib2.HTTPError as exc:
...   print(dir(exc))
['_HTTPError__super_init', '__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__getitem__', '__getslice__', '__hash__', '__init__', '__iter__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setstate__', '__sizeof__', '__str__', '__subclasshook__', '__unicode__', '__weakref__', 'args', 'close', 'code', 'errno', 'filename', 'fileno', 'fp', 'getcode', 'geturl', 'hdrs', 'headers', 'info', 'message', 'msg', 'next', 'read', 'readline', 'readlines', 'strerror', 'url']

The same issue exists in Python 3.2.2.

Here's what I propose:
  - For Python 3.2 and 3.3, update HTTPError to supply a @property, aliasing .msg (will .msg always be a suitable .reason?).
  - For Python 2.7, document the deviance, such as by adding the following wording to the HTTPError docs: "Unlike URLError, HTTPError does not supply a reason attribute. The reason can be retrieved through the msg attribute."

assignee: docs at python
components: Documentation
messages: 145805
nosy: docs at python, jason.coombs
priority: normal
severity: normal
status: open
title: urllib2.HTTPError does not have 'reason' attribute.
versions: Python 2.7, Python 3.2, Python 3.3

Python tracker <report at bugs.python.org>

More information about the docs mailing list