Zope2.9.6+Plone2.5.2
こんな環境に古い環境からコンテンツをimportして表示させるとこんなエラーが。
(中略) File "/usr/local/lib/python/Products/PageTemplates/ZRPythonExpr.py", line 47, in __call__ return eval(code, g, {}) File "Python expression "context.getHeadTitle()"", line 1, in <expression> File "/usr/local/zope/cms/Products/CMFCore/FSPythonScript.py", line 108, in __ call__ return Script.__call__(self, *args, **kw) File "/usr/local/lib/python/Shared/DC/Scripts/Bindings.py", line 311, in __cal l__ return self._bindAndExec(args, kw, None) File "/usr/local/lib/python/Shared/DC/Scripts/Bindings.py", line 348, in _bind AndExec return self._exec(bound_data, args, kw) File "/usr/local/zope/cms/Products/CMFCore/FSPythonScript.py", line 164, in _e xec result = f(*args, **kw) File "Script (Python)", line 60, in getHeadTitle UnicodeDecodeError: 'ascii' codec can't decode byte 0xe3 in position 0: ordinal not in range(128)
何でだーと、"UnicodeDecodeError"と"Plone"でGoogle先生に聞くとここに情報がありました。site.pyのデフォルトエンコードを変更すればいいとのこと。
上記サイトでは/usr/local/lib/python2.4/site.py、つまりインストールされているものを変更せよとなっていますが、それではダメで、Pythonを再インストールする必要があります。
site.pyは開発環境以下の Lib/site.py にありますので、このファイルをエディット。
変更箇所はdef setencoding():のencodingを定義しているところ。
ef setencoding(): """Set the string encoding used by the Unicode implementation. The default is 'ascii', but if you're willing to experiment, you can change this.""" encoding = "utf-8" # Default value set by _PyUnicode_Init() if 0: # Enable to support locale aware default string encodings. import locale loc = locale.getdefaultlocale() if loc[1]: encoding = loc[1] if 0: # Enable to switch off string to Unicode coercion and implicit # Unicode to string conversion. encoding = "undefined" if encoding != "ascii": # On Non-Unicode builds this will raise an AttributeError... sys.setdefaultencoding(encoding) # Needs Python Unicode build !
上記の太字のところ、デフォルトだとasciiになっているのをutf-8に。そして再度コンパイルしてインストール。
$ ./configure --enable-unicode $ /usr/local/bin/make # /usr/local/bin/make install
これで解決しました。