|
68 | 68 | # just logging the environment as first thing |
69 | 69 | logger.debug('===========================================================') |
70 | 70 | logger.debug('Environment of execution host\\n') |
71 | | -for key, val in getattr(os, "environb", os.environ).items(): |
72 | | - # Clean the environment of non-utf-8 characters |
73 | | - try: |
74 | | - key = key.decode("utf-8") |
75 | | - val = val.decode("utf-8") |
76 | | - except UnicodeDecodeError as e: |
77 | | - logger.error("Dropping %%s=%%s due to: %%s", key, val, e) |
78 | | - del os.environ[key] |
79 | | - continue |
80 | | - logger.debug(key + '=' + val) |
| 71 | +# Clear any non-UTF encodable environment variables as they cause the pilot to fail |
| 72 | +# Use os.environb if it exists (gives raw bytes), else fall back to os.environ. |
| 73 | +environb = getattr(os, "environb", os.environ) |
| 74 | +for key, val in environb.items(): |
| 75 | + try: |
| 76 | + # Decode if these are bytes; if they're already text, leave them as-is. |
| 77 | + if isinstance(key, bytes): |
| 78 | + key_decoded = key.decode("utf-8") |
| 79 | + else: |
| 80 | + key_decoded = key |
| 81 | + if isinstance(val, bytes): |
| 82 | + val_decoded = val.decode("utf-8") |
| 83 | + else: |
| 84 | + val_decoded = val |
| 85 | + except UnicodeDecodeError as e: |
| 86 | + logger.error("Dropping %%s=%%s due to decode error: %%s", key, val, e) |
| 87 | + del environb[key] |
| 88 | + continue |
| 89 | +
|
| 90 | + logger.debug(key_decoded + '=' + val_decoded) |
81 | 91 | logger.debug('===========================================================\\n') |
82 | 92 |
|
83 | 93 | # putting ourselves in the right directory |
|
0 commit comments