From 237e497ceedc8b2587048f3dde1d21752ef39397 Mon Sep 17 00:00:00 2001 From: Dario Mapelli Date: Wed, 12 Aug 2020 18:53:40 +0200 Subject: [PATCH] Improve py2 compatibility of WMException __init__ This solves the issue 9862, The rationale for this change is described in the issue comments --- src/python/WMCore/WMException.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/python/WMCore/WMException.py b/src/python/WMCore/WMException.py index 591913a4163..792ca258818 100644 --- a/src/python/WMCore/WMException.py +++ b/src/python/WMCore/WMException.py @@ -6,6 +6,8 @@ """ +from builtins import bytes + import exceptions import inspect import logging @@ -27,7 +29,7 @@ class WMException(exceptions.Exception): def __init__(self, message, errorNo=None, **data): self.name = str(self.__class__.__name__) - if hasattr(message, "decode"): + if type(message) == bytes: # Fix for the unicode encoding issue, see #8056 and #8403 # interprets this string using utf-8 codec and ignoring any errors message = message.decode('utf-8', 'ignore') @@ -151,7 +153,7 @@ def __str__(self): strg += self.traceback strg += '\n' strg += WMEXCEPTION_END_STR - if hasattr(strg, "decode"): + if type(strg) == bytes: # Fix for the unicode encoding issue, #8043 strg = strg.decode('utf-8', 'ignore') return strg