New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
urllib.error.HTTPError(..., fp=None)
raises a KeyError
instead of an AttributeError
on attribute access
#98778
Comments
The problem is that Lines 49 to 50 in 3e07f82
cc @orsenthil |
… None (pythongh-99966) (cherry picked from commit dc8a868) Co-authored-by: Dong-hee Na <donghee.na@python.org>
… None (pythongh-99966) (cherry picked from commit dc8a868) Co-authored-by: Dong-hee Na <donghee.na@python.org>
Great! Thanks for the fix :) Do you think it would be interesting to make diff --git a/Lib/traceback.py b/Lib/traceback.py
index 6270100348..a9c15d59be 100644
--- a/Lib/traceback.py
+++ b/Lib/traceback.py
@@ -694,7 +694,10 @@ def __init__(self, exc_type, exc_value, exc_traceback, *, limit=None,
# Capture now to permit freeing resources: only complication is in the
# unofficial API _format_final_exc_line
self._str = _safe_string(exc_value, 'exception')
- self.__notes__ = getattr(exc_value, '__notes__', None)
+ try:
+ self.__notes__ = getattr(exc_value, '__notes__', None)
+ except Exception:
+ self.__notes__ = None
if exc_type and issubclass(exc_type, SyntaxError):
# Handle SyntaxError's specially |
@vxgmichel |
vxgmichel commentedOct 27, 2022
•
edited by bedevere-bot
Bug report
The exception
urllib.error.HTTPError(..., fp=None)
raises aKeyError
instead of anAttributeError
when accessing an attribute that does not exist.Your environment
This bug should be reproducible for all python3 versions on all systems.
Context
I found this error while running a code similar to this:
Instead of having the exception logged, I ended up with the following trace:
Note however that the exception is logged properly on python 3.9 (without the
exceptiongroup
module imported). So maybe the following patch should be applied on top ofHTTPError
being fixed in order to make tracebacks more robust:Linked PRs
The text was updated successfully, but these errors were encountered: