Make SFTPClient._async_request check basestring, not str #235

Closed
ksamuel opened this Issue Nov 18, 2013 · 1 comment

Projects

None yet

2 participants

@ksamuel
ksamuel commented Nov 18, 2013

Arround line 700, we got :

        for item in arg:
            if isinstance(item, int):
                msg.add_int(item)
            elif isinstance(item, long):
                msg.add_int64(item)
            elif isinstance(item, str):
                msg.add_string(item)
            elif isinstance(item, SFTPAttributes):
                item._pack(msg)
            else:
                raise Exception('unknown type for %r type %r' % (item, type(item)))

Which mean you can't pass subclasses of unicode there. Either you make this check :

isinstance(item, basetring)

Or you make an explicit message explaining you reject non encoded strings. Otherwise, it's hard to understand what's going on when you get :

Exception: unknown type for unicode_subclass(u'/stuff') type <class 'us.us'>
@bitprophet
Member

Thanks for looking out! This should have been fixed in the recent merge of Python 3 support; that line now looks like this: https://github.com/paramiko/paramiko/blob/e032541b787e74510aa66b0a243ffc1d1a61b7f4/paramiko/sftp_client.py#L660 - and string_types under Python 2 is basestring.

This change is live in version 1.13 and I will go backport it to a few older branches that are Python 2 only; their next bugfix releases will have the change.

@bitprophet bitprophet closed this Mar 14, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment