Re: jython 'utf8 encoding not found error

Radosław Madej <[email protected]>
Newsgroups gmane.comp.lang.jython.user
Message-ID <AMSPR05MB437E105A16CA18EB040854C993B0@AMSPR05MB437.eurprd05.prod.outlook.com>
Jeff,

Thx for the reply. Indeed, this was a configuration error. It works now, after changing the code to:

Properties properties = new Properties();
properties.setProperty("python.path", pythonPath);
PythonInterpreter.initialize(System.getProperties(), properties, new String[] { "" });
PythonInterpreter pythonInterpreter = new PythonInterpreter();
pythonInterpreter.exec("import codecs");
pythonInterpreter.exec("codecs.getreader('utf8')");

where pythonPath is the painfully obtained path to somewhere in my deployed .war, where the "Lib" directory with python modules resides. Now I can also explicitly do:

pythonInterpreter.exec("import encodings");

I guess I can wrap it all up in some postConstruct Spring method, which will be invoked when starting Spring context. Am I right that python.path is set once per a ClassLoader? Also, are there any other recommended options to set this property, or the spring initialization seems like an elegant enough solution?

Br.
Radek Madej

From: Jeff Emanuel [mailto:[email protected]]
Sent: Wednesday, February 04, 2015 19:13
To: [email protected]
Subject: Re: [Jython-users] jython 'utf8 encoding not found error

WFM in 2.5.3 in the jython console and in the interpreter embedded in my app.
It's likely a configuration error.

It looks like the encodings are loaded via

                imp.load("encodings");

Can you explicitly import encodings?  If not that might give a clue.  Try turning python.verbose
up to debug for detailed import messages.

pythonInterpreter.exec("import encodings");

On 2/4/2015 2:09 AM, Radosław Madej wrote:
Hi,

I have a problem with jython 'utf8' encoding.

The Jython version I am using is 2.5.3, embedded in my web application. After doing this in my Java code:

PythonInterpreter pythonInterpreter = new PythonInterpreter();

pythonInterpreter.exec("import codecs");

pythonInterpreter.exec("codecs.getreader('utf8')");

Such an error occurs:

File "<string>", line 1, in <module>

File "__pyclasspath__/codecs$py.class", line 920, in getreader

LookupError: no codec search functions registered: can't find encoding 'utf8'

How can the reader with 'utf8' encoding be obtained properly?

According to the python documentation, there should be 'utf8' encoding available in codecs module: https://docs.python.org/2/library/codecs.html#standard-encodings (lower / upper case and hyphen / underscore are all allowed).

I use Windows 7, java 1.7.0_71. OS should not matter I guess - this is the web application run on jboss (version 7.2).

I've also posted the question to the stackoverflow, but no answers yet...:

http://stackoverflow.com/questions/28303395/how-to-obtain-utf-8-reader-in-pythoninterpreter-jython

Br,

Radek





------------------------------------------------------------------------------

Dive into the World of Parallel Programming. The Go Parallel Website,

sponsored by Intel and developed in partnership with Slashdot Media, is your

hub for all things parallel software development, from weekly thought

leadership blogs to news, videos, case studies, tutorials and more. Take a

look and join the conversation now. http://goparallel.sourceforge.net/




_______________________________________________

Jython-users mailing list

[email protected]<mailto:[email protected]>

https://lists.sourceforge.net/lists/listinfo/jython-users

------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/

_______________________________________________
Jython-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jython-users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.