Encode key before querying os.environ on Python 2