[Labs-l] Unicode prints fails in jsub

Merlijn van Deen valhallasw at arctus.nl
Mon May 19 21:53:00 UTC 2014


On 19 May 2014 23:25, Emilio J. Rodríguez-Posada <emijrp at gmail.com> wrote:

> When I test my Python script in tools-dev, prints are OK. But when I
> launch the script with jsub, I receive errors of Unicode:
>
> UnicodeEncodeError: 'ascii' codec can't encode character '\xe9' in
> position 6: ordinal not in range(128)
>
> Why does it change among boxes?
>
>
There are several reasons for this, but the most important one is output
redirection. When writing to a terminal, Python will encode your unicode
string with the current terminal encoding, but for a file, Python needs to
know which encoding to use.

See https://bugzilla.wikimedia.org/show_bug.cgi?id=58784 for some
suggestions. The easiest option is making sure you write bytes to your
output (i.e. explicitly .encode('utf-8') the unicode object).

An easy way to test is running

python scriptname.py | tee

which should give you the same result as jsub -- apart from environment
options.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.wikimedia.org/pipermail/labs-l/attachments/20140519/bec9ec36/attachment.html>


More information about the Labs-l mailing list