Found the fix and it works.
I notice the indentation is screwed up
in stackoverflow -- I put the encoding = 'utf-8' line in line with the try and except preceding it.
This seems to have something to do with the Windows default encoding for stdout not being UTF-8.
encoding = "ascii"
if sys.platform == 'win32':
# On Windows, we could use "mbcs". However, to give the user
# a portable encoding name, we need to find the code page
try:
encoding = locale.getdefaultlocale()[1]
codecs.lookup(encoding)
except LookupError:
pass
encoding = 'utf-8'