From 2af59ea388bccbc969f485e5b2e57b2bbde5a97f Mon Sep 17 00:00:00 2001 From: Johannes Erdfelt Date: Fri, 26 Jul 2013 15:16:13 +0000 Subject: [PATCH] BaseException.message is deprecated since Python 2.6 PEP 352 deprecated the message attribute of the BaseException class. Using the message attribute will result in warnings like this: DeprecationWarning: BaseException.message has been deprecated as of Python 2.6 Using unicode(exc) is the suggested replacement. Change-Id: Ibf3c56e4baa6ad83e2b95a948787e9d02cf074d4 --- openstack/common/excutils.py | 7 ++++--- openstack/common/timeutils.py | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/openstack/common/excutils.py b/openstack/common/excutils.py index abe6f877..664b2e4e 100644 --- a/openstack/common/excutils.py +++ b/openstack/common/excutils.py @@ -77,7 +77,8 @@ def forever_retry_uncaught_exceptions(infunc): try: return infunc(*args, **kwargs) except Exception as exc: - if exc.message == last_exc_message: + this_exc_message = unicode(exc) + if this_exc_message == last_exc_message: exc_count += 1 else: exc_count = 1 @@ -85,12 +86,12 @@ def forever_retry_uncaught_exceptions(infunc): # the exception message changes cur_time = int(time.time()) if (cur_time - last_log_time > 60 or - exc.message != last_exc_message): + this_exc_message != last_exc_message): logging.exception( _('Unexpected exception occurred %d time(s)... ' 'retrying.') % exc_count) last_log_time = cur_time - last_exc_message = exc.message + last_exc_message = this_exc_message exc_count = 0 # This should be a very rare event. In case it isn't, do # a sleep. diff --git a/openstack/common/timeutils.py b/openstack/common/timeutils.py index bd60489e..aa9f7080 100644 --- a/openstack/common/timeutils.py +++ b/openstack/common/timeutils.py @@ -49,9 +49,9 @@ def parse_isotime(timestr): try: return iso8601.parse_date(timestr) except iso8601.ParseError as e: - raise ValueError(e.message) + raise ValueError(unicode(e)) except TypeError as e: - raise ValueError(e.message) + raise ValueError(unicode(e)) def strtime(at=None, fmt=PERFECT_TIME_FORMAT):