diff --git a/wandb/sdk/wandb_run.py b/wandb/sdk/wandb_run.py
index <HASH>..<HASH> 100644
--- a/wandb/sdk/wandb_run.py
+++ b/wandb/sdk/wandb_run.py
@@ -2138,10 +2138,7 @@ class Run(object):
             return logs
 
         # Only print sparklines if the terminal is utf-8
-        # In some python 2.7 tests sys.stdout is a 'cStringIO.StringO' object
-        #   which doesn't have the attribute 'encoding'
-        encoding = getattr(sys.stdout, "encoding", None)
-        if not encoding or encoding.upper() not in ("UTF_8", "UTF-8",):
+        if not is_unicode_safe(sys.stdout):
             return logs
 
         logger.info("rendering history")
diff --git a/wandb/util.py b/wandb/util.py
index <HASH>..<HASH> 100644
--- a/wandb/util.py
+++ b/wandb/util.py
@@ -1318,7 +1318,7 @@ def is_unicode_safe(stream):
     """returns true if the stream supports UTF-8"""
     if not hasattr(stream, "encoding"):
         return False
-    return stream.encoding == "UTF-8"
+    return stream.encoding.lower() in {"utf-8", "utf_8"}
 
 
 def _has_internet():
Fix missing emoji (#<I>)