UnicodeEncodeError with Visual Studio Post-Build C

2019-08-18 02:31发布

问题:

I am trying to run a Python script from a Visual Studio C/C++ project's Post-Build Command Line. The arguments for the script contain German Umlauts, let's say Ü. The Command Line Script is

python "<path to python .py>" Ü

The Python script simply prints the first (second) argument back to the Command Line:

import sys

if __name__ == "__main__":
    print(sys.argv[1])

However, this raises an exception for the last line:

...

File "C:\Python36\lib\encoding\cp1252.py", line 19, in encode

return codecs.charmap_encode(input, self.errors, encoding_table)[0]

UnicodeEncodeError: 'charmap' codec can't encode character '\u2584' in position 0: character maps to < undefined >

How to solve this?