This question is related to Getting file path with umlauts from command line arguments under win7 using a batch file but has another twist. I installed win_unicode_console. I opened a console window and change the codepage via chcp.com 65001 > nul then I started a python script inside a path with umlauts which works fine in this console but the program throws this error:
Traceback (most recent call last):
File "C:\path\to\script.py",
line 205, in <module>
print err
File "C:\python27\lib\site-packages\win_unicode_console\streams.py", line 256,
in write
self.base.write(s)
File "C:\python27\lib\site-packages\win_unicode_console\streams.py", line 216,
in write
return self.base.write(s)
File "C:\python27\lib\site-packages\win_unicode_console\streams.py", line 165,
in write
raise exc
WindowsError:
The program complaints about "print err" because this is the way I try to capture the exception:
try:
... main code ...
except Exception, err:
print err
Inside the ... main code ... part there is a line
print 'ausgewählte Konfiguration:'
This 'ä' character causes the error but I do not understand why. I tried everything I can to make the encoding right but the console output crashes everything.
If I do not change the codepage of the console via chcp , as eryksun suggested, the error is gone but there is a new problem. The script receives a filepath containing special characters like "ä". The script opens the file without problems in the first place but writing data back is not possible
'utf8' codec can't decode byte 0xe4 in position 4: invalid continuation byte