14.01.2011 02:24, claudef@br.ibm.com kirjoitti:
Dear Alex and Marcel,

Excuse me to ask. Why it won't work ?  Observing the error message, I see a clear sign the the character delivered by the query is above the 7 bit boundary. See the error message:

UnicodeEncodeError: 'ascii' codec can't encode character u'\xe1' in position 11: ordinal not in range(128)

             Character "á" = x'E1' Dec 225 is a typical Latin Character  

The encoding "Latin1" is a common  8 bit extended ASCII representation which should accept the 8 bit characters delivered by the query,

So the statement   sys.setdefaultencoding("latin1")  has a good chance to work O.K.

However you are able to translate a string regardless of its current encoding used by Jython, by adding the function encode("Latin1), or encode("UTF-8") if you prefer so. This is another solution that should work in the Jython release 2.5.x.

This is because the "sys" module does not HAVE a "setdefaultencoding" function during runtime!
Let me paste you the documentation from python.org:

setdefaultencoding(name)
    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. New in version 2.0.
What I can say, give it a trial.

Regards,
Claude

Claude Falbriard
Certified IT Specialist L2 - Middleware
AMS Hortolândia / SP - Brazil
phone:    +55 13 9762 4094
cell:         +55 13 8117 3316
e-mail:    claudef@br.ibm.com




From:        Alex Grönholm <alex.gronholm@nextday.fi>
To:        jython-users@lists.sourceforge.net
Date:        13/01/2011 21:12
Subject:        Re: [Jython-users] dbexts UnicodeEncodeError




13.01.2011 17:38, claudef@br.ibm.com kirjoitti:
Dear Marcel,

give this a trial with:


sys.setdefaultencoding("latin1")

This one won't work.

or

mystr = mystr.encode('latin1')


Regards,
Claude


Claude Falbriard
Certified IT Specialist L2 - Middleware
AMS Hortolândia / SP - Brazil
phone:    +55 13 9762 4094
cell:         +55 13 8117 3316
e-mail:    
claudef@br.ibm.com




From:        
marcel liker <m_liker@yahoo.com>
To:        
jython-users <jython-users@lists.sourceforge.net>
Date:        
13/01/2011 12:27
Subject:        
[Jython-users] dbexts UnicodeEncodeError




Hi all,
is the below example expected behavior of dbexts console formater?

>>> db.isql("select * from table where condition)

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/user/jython252rc2/Lib/dbexts.py", line 332, in isql
  self.display()
File "/home/user/jython252rc2/Lib/dbexts.py", line 312, in display
  for a in self.formatter(res, map(lambda x: x[0], self.headers)):
File "/home/user/jython252rc2/Lib/dbexts.py", line 85, in console
  row = map(lambda x: str(x), row)
File "/home/user/jython252rc2/Lib/dbexts.py", line 85, in <lambda>
  row = map(lambda x: str(x), row)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe1' in position 11: ordinal not in range(128)

While:

>>> print db.results[0][2]
Ignácio

And from the above trace:

>>> str(prod.results[0][2])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe1' in position 11: ordinal not in range(128)

I also tested this with 2.5.2rc3 and the behavior is the same.

Tested on sles 10 with java1.6.0_14