[Cubicweb] cubicweb-ctl shell: encoding
Aurélien Campéas
aurelien.campeas at logilab.fr
Wed Sep 25 18:30:38 CEST 2013
On 25/09/2013 17:13, Dimitri Papadopoulos Orfanos wrote:
> Hi,
>
> Please consider the following script:
>
> import locale
>
> encoding = locale.getpreferredencoding()
> print encoding
>
> import os
>
> pwd = os.getcwd()
> pwd = pwd.decode(encoding)
> print pwd
>
>
>
> If we run it directly from Python it works:
> $ python myscript.py
> UTF-8
> /volatile/Téléchargements
> $
>
>
> If we run it from the CubicWeb shell it fails:
> $ cubicweb-ctl shell test myscript.py
> UTF-8
> ...
> File "myscript.py", line 10, in <module>
> print pwd
> UnicodeEncodeError: 'ascii' codec can't encode
> character u'\xe9' in position 20:
> ordinal not in range(128)
> $
>
>
> What is causing this? Any clue on how we should be fixing our code?
>
You can try:
* fixing your non-ascii paths
* NOT printing unicode strings (that's quite cheap)
See
http://stackoverflow.com/questions/492483/setting-the-correct-encoding-when-piping-stdout-in-python
for an overview of the (general) problem.
Aurélien.
More information about the Cubicweb
mailing list