Issue #8391: os.execvpe() and os.getenv() supports unicode with surrogates and
bytes strings for environment keys and values
diff --git a/Lib/os.py b/Lib/os.py
index 580b983..7672d6f 100644
--- a/Lib/os.py
+++ b/Lib/os.py
@@ -450,6 +450,8 @@
 def getenv(key, default=None):
     """Get an environment variable, return None if it doesn't exist.
     The optional second argument can specify an alternate default."""
+    if isinstance(key, bytes):
+        key = key.decode(sys.getfilesystemencoding(), "surrogateescape")
     return environ.get(key, default)
 __all__.append("getenv")