@@ -110,16 +110,26 @@ def formatTime(self, record, datefmt=None):
110110# just logging the environment as first thing
111111logger.debug('===========================================================')
112112logger.debug('Environment of execution host\\ n')
113- for key, val in getattr(os, "environb", os.environ).items():
114- # Clean the environment of non-utf-8 characters
115- try:
116- key = key.decode("utf-8")
117- val = val.decode("utf-8")
118- except UnicodeDecodeError as e:
119- logger.error("Dropping %%s=%%s due to: %%s", key, val, e)
120- del os.environ[key]
121- continue
122- logger.debug(key + '=' + val)
113+ # Clear any non-UTF encodable environment variables as they cause the pilot to fail
114+ # Use os.environb if it exists (gives raw bytes), else fall back to os.environ.
115+ environb = getattr(os, "environb", os.environ)
116+ for key, val in environb.items():
117+ try:
118+ # Decode if these are bytes; if they're already text, leave them as-is.
119+ if isinstance(key, bytes):
120+ key_decoded = key.decode("utf-8")
121+ else:
122+ key_decoded = key
123+ if isinstance(val, bytes):
124+ val_decoded = val.decode("utf-8")
125+ else:
126+ val_decoded = val
127+ except UnicodeDecodeError as e:
128+ logger.error("Dropping %%s=%%s due to decode error: %%s", key, val, e)
129+ del environb[key]
130+ continue
131+
132+ logger.debug(key_decoded + '=' + val_decoded)
123133logger.debug('===========================================================\\ n')
124134
125135logger.debug(sys.version)
0 commit comments