Context
I have a generator that constantly outputs every line from a specific command (see code snippet below, code taken from here).
def execute(cmd):
popen = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True, universal_newlines=True)
for stdoutLine in iter(popen.stdout.readline, ""):
yield stdoutLine.rstrip('\r|\n')
The issue
The issue is, the stdout line can have special characters that cp1252 could not handle. (see multiple error messages below, each from a different test)
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 6210: character maps to <undefined>
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 3691: character maps to <undefined>
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 6228: character maps to <undefined>
Question
What should I do to handle these special characters?