3

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 ?

http://web.archiveorange.com/archive/v/8tc1Zc2rV3qiUcy9zPlA

Houtman
  • 2,819
  • 2
  • 24
  • 34

3 Answers3

3

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.

Aaron
  • 915
  • 9
  • 21
1

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.

http://docs.python.org/library/sys.html

Serdalis
  • 10,296
  • 2
  • 38
  • 58
Dmitry Zagorulkin
  • 8,370
  • 4
  • 37
  • 60
  • I tried both, but that didn't change anything?! The # at the very first line. And sys.setdefaultencoding after import.sys. But then it says systemstate has no attribute 'setdefaultencoding'.. Looks like something else already executed it. – Houtman Aug 28 '12 at 12:22
  • I came to the conclusion the problem lies somewhere else in Jython, so i completely revised the question. – Houtman Aug 29 '12 at 09:40
0

It is Jython Bugs issue #1066:

http://bugs.jython.org/issue1066

Houtman
  • 2,819
  • 2
  • 24
  • 34