When on the shell, your terminal will be trying to translate the byte string to printable chars. It's possible some of the bytes aren't valid chars at all so copy-pasting them is useless.
The easiest was to deal with non-printable filenames on the shell is to use get a file's inode then use find
to do something with it.
To get a file's inode:
ls -il
The first column is the inode. Pass this to find:
find . -inum <inode-number> -exec mv {} newfilename.msg \;
In Python, the trick is open a file with an odd name is to do a file list and pass the resulting string to open
.
For example:
os.listdir('/var/tmp/attachment/')