[Cubicweb] cubicweb-ctl shell: encoding

Dimitri Papadopoulos Orfanos dimitri.papadopoulos at cea.fr
Wed Sep 25 17:13:09 CEST 2013


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?

-- 
Dimitri Papadopoulos
CEA/Saclay
I2BM, NeuroSpin
F-91191 Gif-sur-Yvette cedex, France



More information about the Cubicweb mailing list