Jython 'unknown enocoding ms932' on japanese system
-
28-06-2021 - |
Question
i've written a program in Jython 2.5.1 which works fine on my Windows 7 machine, but on a japanese machine it throws an Exception saying "unknown encoding 'ms932'"
i found that codecs.java is the only module printing the unknown encoding 'xyz' message
this file loads aliases.py which does contain
# cp932 codec
'932' : 'cp932',
'ms932' : 'cp932',
'mskanji' : 'cp932',
'ms_kanji' : 'cp932',
The file cp932.py contains
import _codecs_jp, codecs
But.. _codecs_jp does not exist as is also discussed in this page Does anyone have a clue where to go from here ?
Solution 3
It is Jython Bugs issue #1066:
OTHER TIPS
Japanese-language bloggers and whatnot recommend the following, and it works for me as well:
Call jython with the argument -C utf-8
.
Note that apparently there are still some limitations, such as the inability to access Japanese pathnames or print Japanese to the console. I haven't encountered these, so I can't comment on workarounds.
you should use sys.setdefaultencoding
i.e.
sys.setdefaultencoding(name)
or just put
# -*- coding: utf-8 -*-
at the head of your script.
Set the current default string encoding used by the Unicode implementation. If name does not match any available encoding, LookupError is raised. This function is only intended to be used by the site module implementation and, where needed, by sitecustomize. Once used by the site module, it is removed from the sys module’s namespace.