Issue #13211: Add .reason attribute to HTTPError to implement parent class (URLError) interface.
diff --git a/Lib/urllib/error.py b/Lib/urllib/error.py
index 300c3fe..40add41 100644
--- a/Lib/urllib/error.py
+++ b/Lib/urllib/error.py
@@ -52,6 +52,12 @@
def __str__(self):
return 'HTTP Error %s: %s' % (self.code, self.msg)
+ # since URLError specifies a .reason attribute, HTTPError should also
+ # provide this attribute. See issue13211 for discussion.
+ @property
+ def reason(self):
+ return self.msg
+
# exception raised when downloaded size does not match content-length
class ContentTooShortError(URLError):
def __init__(self, message, content):