Using SFTP pull on Win32

John A Meinel john at arbash-meinel.com
Fri Nov 11 15:05:01 GMT 2005


Alexey Shamrin wrote:
> On 11/11/05, Matt Lavin <matt.lavin at gmail.com> wrote:
>> I've recently grabbed the 0.6 version of bzr to test out the new SFTP
>> support and I was wondering how well it works on Windows.  Everything
>> I've tried so far seems to work, after I applied a single change.
>> Whenever bzr connects to my sftp server and tries to prompt me for a
>> password I get an error about how getpass() fails when displaying
>> unicode characters.  I tracked the problem down to _username, and _host
>> are unicode, but putch() only accepts chars.  I should have copied the
>> error message before fixing it, but I can reproduce it again if somebody
>> needs it.  The change I made to make it work on my machine is to wrap
>> the two arguments in str() calls to convert them back to non-unicode
>> format.  I'm not sure how well this would work if the username has
>> unicode characters, but I thought I should post to the list in case
>> somebody else can have a nice solution.  In the end, I changed a line in
>> bzrlib/transport/sftp.py from
>>
>>         password = getpass.getpass('SSH %s@%s password: ' %
>> (self._username, self._host))
>>
>>  to
>>
>>       password = getpass.getpass('SSH %s@%s password: ' %
>> (str(self._username), str(self._host)))
> 
> I agree, without the fix "bzr pull" fails (see the end of the message
> for traceback).
> 
> I think the better way to fix the bug is to encode the arguments using
> sys.stdout.encoding, because getpass always write to stoud. Here is
> the patch:

I agree that this is the way to fix the problem. With one minor fix. I
would use "self._username.encode(enc, errors='replace')".
Because this is just displaying the username, and it is possible that
those characters are illegal in the current encoding.
Otherwise you get a UnicodeEncodeError if there is an illegal character.

John
=:->

> 
> === modified file 'bzrlib\\transport\\sftp.py'
> --- bzrlib\transport\sftp.py
> +++ bzrlib\transport\sftp.py
> @@ -446,7 +446,8 @@
>                 pass
> 
>         # give up and ask for a password
> -        password = getpass.getpass('SSH %s@%s password: ' %
> (self._username, self._host))
> +        enc = sys.stdout.encoding
> +        password = getpass.getpass('SSH %s@%s password: ' %
> (self._username.encode(enc), self._host.encode(enc)))
>         try:
>             transport.auth_password(self._username, password)
>         except paramiko.SSHException:
> 
> 
> This fix not only makes "bzr pull" working, but also "bzr push"!
> 
> 
> Error message and a traceback
> =====================================
> 
> c:\work\prog\soft>bzr pull
> Using saved location: sftp://user@li11-40.members.linode.com/home/user/prog
> bzr: ERROR: putch() argument 1 must be char, not unicode
>  command: 'c:\\soft\\python\\scripts\\bzr' 'pull'
>      pwd: u'c:\\work\\prog\soft'
>    error: exceptions.TypeError
>  at c:\soft\python\lib\getpass.py line 49, in win_getpass()
>  see ~/.bzr.log for debug information
> 
> Extract from the log:
> 
> Traceback (most recent call last):
>  File "c:\work\prog\bzr\bzr.dev\bzrlib\commands.py", line 531, in
> run_bzr_catch_errors
>    return run_bzr(argv)
>  File "c:\work\prog\bzr\bzr.dev\bzrlib\commands.py", line 506, in run_bzr
>    ret = cmd_obj.run_argv(argv)
>  File "c:\work\prog\bzr\bzr.dev\bzrlib\commands.py", line 225, in run_argv
>    return self.run(**all_cmd_args)
>  File "c:\work\prog\bzr\bzr.dev\bzrlib\builtins.py", line 382, in run
>    br_from = Branch.open(location)
>  File "c:\work\prog\bzr\bzr.dev\bzrlib\branch.py", line 119, in open
>    t = get_transport(base)
>  File "C:\work\prog\bzr\bzr.win32\bzrlib\transport\__init__.py", line
> 352, in get_transport
>    return klass(base)
>  File "C:\work\prog\bzr\bzr.win32\bzrlib\transport\__init__.py", line
> 367, in _loader
>    return klass(base)
>  File "c:\work\prog\bzr\bzr.dev\bzrlib\transport\sftp.py", line 97, in __init__
>    self._sftp_connect()
>  File "c:\work\prog\bzr\bzr.dev\bzrlib\transport\sftp.py", line 417,
> in _sftp_connect
>    self._sftp_auth(t, self._username, self._host)
>  File "c:\work\prog\bzr\bzr.dev\bzrlib\transport\sftp.py", line 449,
> in _sftp_auth
>    password = getpass.getpass('SSH %s@%s password: ' %
> (self._username, self._host))
>  File "c:\soft\python\lib\getpass.py", line 49, in win_getpass
>    msvcrt.putch(c)
> TypeError: putch() argument 1 must be char, not unicode
> 
> --
> Alexey
> 
> 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 249 bytes
Desc: OpenPGP digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20051111/1ebfa9fd/attachment.pgp 


More information about the bazaar mailing list