Skip to content

Unicode issue #54

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gipi opened this issue Feb 21, 2016 · 2 comments
Closed

Unicode issue #54

gipi opened this issue Feb 21, 2016 · 2 comments

Comments

@gipi
Copy link

gipi commented Feb 21, 2016

I'm trying to use parallel-ssh in a project of mine and all it's working fine, only I noticed that if I launch the command lsblk in the remote side an exception is raised

Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/opt/deplopy/deplopy/deplopy/deplopy.py", line 83, in <module>
    for stdout in output[host]['stdout']:
  File "/opt/deplopy/.virtualenv/local/lib/python2.7/site-packages/pssh/ssh_client.py", line 240, in _read_output_buffer
    output = line.strip().decode('ascii')
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 0: ordinal not in range(128)

If I log in the machine with ssh all it's working fine, the character that is causing trouble is the
first in the third line of the output

NAME   MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda    254:0    0  20G  0 disk
└─vda1 254:1    0  20G  0 part /

i.e. , If I remove decode('ascii') from the ssh_client code all it's working fine.

I'm not proposing a patch because I'm not sure what the decode function should do in this case, my guess is that is for terminal compatibility.

Seems strange to me that I'm the first to encounter such issue, but I searched on github without any luck, so here we are.

@pkittenis
Copy link
Member

Thanks for raising! Fixed in master branch.

NB - the ascii decode was added for forwards compatibility with py3 which uses byte buffers by default and need decoding into strings.

Changing the decode to utf8 seems to resolve the issue though obviously exotic terminal encodings may still cause issues.

Perhaps the client should check character encoding via $LANG and convert accordingly.. Some testing if you have non utf8 or ascii terminals lying around would be appreciated.

@pkittenis
Copy link
Member

From latest master branch:

In [1]: from pssh import ParallelSSHClient

In [2]: client = ParallelSSHClient(['localhost'])

In [3]: output = client.run_command('lsblk')

In [4]: for line in output['localhost']['stdout']: print line
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 238.5G  0 disk
├─sda1   8:1    0  62.7G  0 part
├─sda2   8:2    0   1.9G  0 part
└─sda3   8:3    0 173.9G  0 part /
sr0     11:0    1  1024M  0 rom

pip install https://github.com/pkittenis/parallel-ssh/archive/master.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants