[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Fab-user] remote host output encoding
From: |
Jeff Forcier |
Subject: |
Re: [Fab-user] remote host output encoding |
Date: |
Wed, 2 Oct 2013 08:55:10 -0700 |
Unfortunately, Fabric isn't great with Unicode at the moment so
there's no 'easy way' you're overlooking. If you're worried that you
can't reliably .decode('utf-8'), which is the usual thing I see folks
do here (in general - not necessarily in fab) then I think your remote
encoding test probably is a good place to start.
Could maybe also test e.g. 'echo $LANG' but if you know the remote
node has Python already, using the locale module is a nice shortcut.
-Jeff
On Tue, Oct 1, 2013 at 8:30 PM, Mike Miller <address@hidden> wrote:
> Hi,
>
> I've been searching for information on character encoding and fabric but
> coming up empty. I've got a command printing an occasional Unicode char and
> so when using the result object I get a UnicodeDecodeError:
>
> output = run('unicode_printer')
>
> 'returned: ' + output # kaboom
>
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 0:
> ordinal not in range(128)
>
> What should I do about this? I could hard-code it to decode with utf8, but
> can't guarantee it will be utf8. I can imagine running a command earlier to
> get the encoding and then decoding it. For example:
>
> encoding = run("python2 -c 'import locale; " +
> "print locale.getdefaultlocale()[1]'")
>
> output = run('unicode_printer')
>
> 'returned: ' + output.decode(encoding)
>
> Wondering if there was a parameter or easier way that I'm missing.
>
> Thanks,
>
>
> _______________________________________________
> Fab-user mailing list
> address@hidden
> https://lists.nongnu.org/mailman/listinfo/fab-user
--
Jeff Forcier
Unix sysadmin; Python/Ruby engineer
http://bitprophet.org