Hi I use twisted library to connect to FTP server but I have problem with filename encoding. I receive 'Illusion-N\xf3z.txt' so its not unicode. Is there any FTP command to force specific encoding? Thanks in advance! MK
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
There are two possibilities:
FEAT
command to see ifUTF8
is there (but it probably isn't, since the example bytes are not valid UTF-8). If it is, decode the bytes using UTF-8.Twisted's FTP client won't do anything unicode-related for it, since it just implements the basic FTP RFC.
FTP ignores encodings; as long as a filename does not contain a
'\0'
(null character) and'/'
(slash) separates directories, it happily accepts anything.Do your own decoding and encoding of the filenames. It is quite probable that the encoding used in your example is "cp1252", which is the “Windows Western” or something like that.
In your case, when you receive 'Illusion-N\xf3z.txt', convert it to Unicode by
'Illusion-N\xf3z.txt'.decode('cp1252')
.