[Cubicweb] cubicweb-ctl shell: encoding
Dimitri Papadopoulos Orfanos
dimitri.papadopoulos at cea.fr
Wed Sep 25 21:53:59 CEST 2013
Hi,
We did get rid of this specific non-ascii path for the time-being.
Still, I would like to fix this issue to avoid future errors.
We print the string to debug a similar failure that otherwise happens
later on in our code - for example when calling unicode() on the string
to feed it to CubicWeb.
Le 25/09/2013 18:30, Aurélien Campéas a écrit :
> 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.
>
> _______________________________________________
> Cubicweb mailing list
> Cubicweb at lists.cubicweb.org
> http://lists.cubicweb.org/mailman/listinfo/cubicweb
--
Dimitri Papadopoulos
CEA/Saclay
I2BM, NeuroSpin
91191 Gif-sur-Yvette cedex, France
More information about the Cubicweb
mailing list