Python 2.6
Linux (CentOS)
I using shutil.copyfile() function to copy file. I write an exception message in the log file if file is doesn't exist. So, i get message with wrong symbols, because my file path contains russian characters. For example:
origin file path - "/PNG/401/405/018_/01200Г/osv_1.JPG" ('Г' it is russian symbol)
file path in message - "/PNG/401/405/018_/01200\xd0\x93/osv_1.JPG"
I'm tried to use this code print(str(error).decode('utf-8')) but it's doesn't work. But this code
print(os.listdir(r'/PNG/401/405/018_/')[0].decode('utf-8')) work pretty well. Any ideas?
Well the output is perfectly correct. 'Г' is the unicode character U+0413 (CYRILLIC CAPITAL LETTER GHE) and its UTF-8 encoding is the 2 characters '\xd0' and '\x93'. You simply have to read the log file with an utf8 enabled text editor (gvim or notepad++ are), or if you have to process it in Python make sure to read it as an utf8 encoded file.
IOError return message with broken encoding