[PR #6959] [CLOSED] Exception.message was deprecated in Python 2.6 and removed in Python 3 #13193

Closed
opened 2025-12-29 22:25:54 +01:00 by adam · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/netbox-community/netbox/pull/6959
Author: @cclauss
Created: 8/14/2021
Status: Closed

Base: developHead: patch-2


📝 Commits (2)

  • dc604ac Exception.message was deprecated in Python 2.6 and removed in Python 3
  • e0751b2 Exception.message was deprecated in Python 2.6 and removed in Python 3

📊 Changes

2 files changed (+2 additions, -2 deletions)

View changed files

📝 netbox/extras/models/customfields.py (+1 -1)
📝 netbox/netbox/models.py (+1 -1)

📄 Description

BaseException.message was deprecated as of Python 2.6 and is removed in Python 3. Use str(e) to access the user-readable message. Use e.args to access arguments passed to the exception.

https://docs.python.org/3/whatsnew/2.6.html#deprecations-and-removals

$ python3


>>> dir(Exception('Hey'))
['__cause__', '__class__', '__context__', '__delattr__', '__dict__', '__dir__',
 '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__',
 '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__ne__',
 '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__',
 '__setstate__', '__sizeof__', '__str__', '__subclasshook__',
 '__suppress_context__', '__traceback__', 'args', 'with_traceback']
>>> try:
...     blah
... except Exception as e:
...     print(e)
...     print(e.args)
...     print(e.message)  # Will cause a second Exception
...     
name 'blah' is not defined
("name 'blah' is not defined",)
Traceback (most recent call last):
  File "<string>", line 2, in <module>
NameError: name 'blah' is not defined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<string>", line 6, in <module>
AttributeError: 'NameError' object has no attribute 'message'

Fixes:


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/netbox-community/netbox/pull/6959 **Author:** [@cclauss](https://github.com/cclauss) **Created:** 8/14/2021 **Status:** ❌ Closed **Base:** `develop` ← **Head:** `patch-2` --- ### 📝 Commits (2) - [`dc604ac`](https://github.com/netbox-community/netbox/commit/dc604ac442da8ff5fdffa0278e0043cbaf63dd01) Exception.message was deprecated in Python 2.6 and removed in Python 3 - [`e0751b2`](https://github.com/netbox-community/netbox/commit/e0751b2a3ab63a11e7c4112f7a7fda5a82c8f460) Exception.message was deprecated in Python 2.6 and removed in Python 3 ### 📊 Changes **2 files changed** (+2 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `netbox/extras/models/customfields.py` (+1 -1) 📝 `netbox/netbox/models.py` (+1 -1) </details> ### 📄 Description `BaseException.message` was deprecated as of Python 2.6 and is removed in Python 3. Use `str(e)` to access the user-readable message. Use `e.args` to access arguments passed to the exception. https://docs.python.org/3/whatsnew/2.6.html#deprecations-and-removals $ `python3` ``` >>> dir(Exception('Hey')) ['__cause__', '__class__', '__context__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setstate__', '__sizeof__', '__str__', '__subclasshook__', '__suppress_context__', '__traceback__', 'args', 'with_traceback'] >>> try: ... blah ... except Exception as e: ... print(e) ... print(e.args) ... print(e.message) # Will cause a second Exception ... name 'blah' is not defined ("name 'blah' is not defined",) Traceback (most recent call last): File "<string>", line 2, in <module> NameError: name 'blah' is not defined During handling of the above exception, another exception occurred: Traceback (most recent call last): File "<string>", line 6, in <module> AttributeError: 'NameError' object has no attribute 'message' ``` <!-- Thank you for your interest in contributing to NetBox! Please note that our contribution policy requires that a feature request or bug report be opened for approval prior to filing a pull request. This helps avoid wasting time and effort on something that we might not be able to accept. Please indicate the relevant feature request or bug report below. IF YOUR PULL REQUEST DOES NOT REFERENCE AN ACCEPTED BUG REPORT OR FEATURE REQUEST, IT WILL BE MARKED AS INVALID AND CLOSED. --> ### Fixes: <ISSUE NUMBER GOES HERE> <!-- Please include a summary of the proposed changes below. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
adam added the pull-request label 2025-12-29 22:25:54 +01:00
adam closed this issue 2025-12-29 22:25:55 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#13193