[ftputil] Handling error messages with accented characters

Roger Demetrescu roger.demetrescu at gmail.com
Wed Apr 16 04:10:11 CEST 2014


Hi Stefan


I've find an issue with ftputil 3.0 when trying to use host.makedirs() and
part of the path already exists AND the FTP server gives error messages
with accented characters.

I created 2 virtualenvs:

- python 2.7   (also happens with python 2.6)
- ftputil 2.8 and ftputil 3.0

FTP Server messages are in brazilian portuguese language.

When I use:
   host.makedirs('/aaa/bbb/ccc')

and /aaa doesn't exist, all directories are created successfully.


BUT, when "/aaa" already exists, that's what happens:

==== ftputil 2.8 ====
>>> host.makedirs('/aaa/bbb/ccc')
*cmd* 'CWD /'
*put* 'CWD /\r\n'
*get* '250 CWD command successful.\r\n'
*resp* '250 CWD command successful.'
*cmd* 'CWD /'
*put* 'CWD /\r\n'
*get* '250 CWD command successful.\r\n'
*resp* '250 CWD command successful.'
*cmd* 'MKD aaa'
*put* 'MKD aaa\r\n'
*get* '550 aaa: N\xe3o \xe9 poss\xedvel criar um arquivo j\xe1
existente.\r\n'
*resp* '550 aaa: N\xe3o \xe9 poss\xedvel criar um arquivo j\xe1 existente.'
*cmd* 'CWD /'
*put* 'CWD /\r\n'
*get* '250 CWD command successful.\r\n'
*resp* '250 CWD command successful.'
*cmd* 'CWD /'
*put* 'CWD /\r\n'
*get* '250 CWD command successful.\r\n'
*resp* '250 CWD command successful.'
*cmd* 'CWD /aaa'
*put* 'CWD /aaa\r\n'
*get* '250 CWD command successful.\r\n'
*resp* '250 CWD command successful.'
*cmd* 'MKD bbb'
*put* 'MKD bbb\r\n'
*get* '257 "bbb" directory created.\r\n'
*resp* '257 "bbb" directory created.'
*cmd* 'CWD /'
*put* 'CWD /\r\n'
*get* '250 CWD command successful.\r\n'
*resp* '250 CWD command successful.'
*cmd* 'CWD /'
*put* 'CWD /\r\n'
*get* '250 CWD command successful.\r\n'
*resp* '250 CWD command successful.'
*cmd* 'CWD /aaa/bbb'
*put* 'CWD /aaa/bbb\r\n'
*get* '250 CWD command successful.\r\n'
*resp* '250 CWD command successful.'
*cmd* 'MKD ccc'
*put* 'MKD ccc\r\n'
*get* '257 "ccc" directory created.\r\n'
*resp* '257 "ccc" directory created.'
*cmd* 'CWD /'
*put* 'CWD /\r\n'
*get* '250 CWD command successful.\r\n'
*resp* '250 CWD command successful.'


==== ftputil 3.0 ====
>>> host.makedirs('/aaa/bbb/ccc')
*cmd* u'CWD /'
*put* u'CWD /\r\n'
*get* '250 CWD command successful.\r\n'
*resp* '250 CWD command successful.'
*cmd* u'CWD /'
*put* u'CWD /\r\n'
*get* '250 CWD command successful.\r\n'
*resp* '250 CWD command successful.'
*cmd* u'MKD aaa'
*put* u'MKD aaa\r\n'
*get* '550 aaa: N\xe3o \xe9 poss\xedvel criar um arquivo j\xe1
existente.\r\n'
*resp* '550 aaa: N\xe3o \xe9 poss\xedvel criar um arquivo j\xe1 existente.'
*cmd* u'CWD /'
*put* u'CWD /\r\n'
*get* '250 CWD command successful.\r\n'
*resp* '250 CWD command successful.'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File
"/home/roger/.virtualenvs/version30/local/lib/python2.7/site-packages/ftputil/host.py",
line 628, in makedirs
    self.mkdir(next_directory)
  File
"/home/roger/.virtualenvs/version30/local/lib/python2.7/site-packages/ftputil/host.py",
line 608, in mkdir
    self._robust_ftp_command(command, path)
  File
"/home/roger/.virtualenvs/version30/local/lib/python2.7/site-packages/ftputil/host.py",
line 574, in _robust_ftp_command
    return command(self, tail)
  File
"/home/roger/.virtualenvs/version30/local/lib/python2.7/site-packages/ftputil/host.py",
line 607, in command
    self._session.mkd(path)
  File
"/home/roger/.virtualenvs/version30/local/lib/python2.7/site-packages/ftputil/error.py",
line 128, in __exit__
    if exc_value.args and exc_value.args[0].startswith("502"):
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe3 in position 10:
ordinal not in range(128)

=============


The error message in pt_br is "Não é possível criar um arquivo já
existente."

Is there anything I can do make it work ?


Thanks in advance !


Best regards
Roger
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sschwarzer.net/pipermail/ftputil/attachments/20140415/22dfe602/attachment.html>


More information about the ftputil mailing list