Issue1585

classification
Title: UnicodeEncodeError when unicode error message in exception is extracted
Type: behaviour Severity: normal
Components: Core Versions: 2.5.1
Milestone:
process
Status: closed Resolution: invalid
Dependencies: Superseder:
Assigned To: Nosy List: AndreasEK, pekka.klarck, pjenvey
Priority: Keywords:

Created on 2010-03-28.20:48:46 by AndreasEK, last changed 2010-03-28.23:40:05 by pekka.klarck.

Messages
msg5601 (view) Author: Andreas Ebbert-Karroum (AndreasEK) Date: 2010-03-28.20:48:45
Jython behaves differently that Python does in this respect:

C:\Dokumente und Einstellungen\aek>\Programme\Python2.6\python.exe
Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> try:
...     raise Exception(u'Flie\xdftext')
... except Exception, e:
...     print e
...
Traceback (most recent call last):
  File "<stdin>", line 4, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character u'\xdf' in position 4: ordinal not in range(128)
>>> try:
...     raise Exception(u'Flie\xdftext')
... except Exception, e:
...     print unicode(e)
...
Fließtext
>>>
>>> ^Z


C:\Dokumente und Einstellungen\aek>\Programme\jython2.5.1\jython.bat
Jython 2.5.1 (Release_2_5_1:6813, Sep 26 2009, 13:47:54)
[Java HotSpot(TM) Client VM (Sun Microsystems Inc.)] on java1.6.0_15
Type "help", "copyright", "credits" or "license" for more information.
>>> try:
...     raise Exception(u'Flie\xdftext')
... except Exception, e:
...     print e
...
Traceback (most recent call last):
  File "<stdin>", line 4, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character u'\xdf' in position 4: ordinal not in range(128)
>>> try:
...     raise Exception(u'Flie\xdftext')
... except Exception, e:
...     print unicode(e)
...
Traceback (most recent call last):
  File "<stdin>", line 4, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character u'\xdf' in position 4: ordinal not in range(128)
>>>
msg5602 (view) Author: Pekka Klärck (pekka.klarck) Date: 2010-03-28.21:33:00
This is probably the easiest way to reproduce this:
>>> unicode(Exception(u'\xe4'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe4' in position 0: ordinal not in range(128)

Interestingly this works:
>>> unicode(Exception(u'\xe4').args[0])
u'\xe4'

I used Jython 2.5.1 to test this. With Python 2.6.2 both of the above examples return u'\xe4' as expected.
msg5603 (view) Author: Philip Jenvey (pjenvey) Date: 2010-03-28.23:05:12
We match CPython 2.5 behavior, this changed in 2.6
msg5604 (view) Author: Pekka Klärck (pekka.klarck) Date: 2010-03-28.23:40:05
Philip is definitely right:

Python 2.5.4 (r254:67916, Jan 20 2010, 21:44:03) 
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> unicode(Exception(u'\xe4'))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe4' in position 0: ordinal not in range(128)
>>> unicode(Exception(u'\xe4').args[0])
u'\xe4'
History
Date User Action Args
2010-03-28 23:40:05pekka.klarcksetmessages: + msg5604
2010-03-28 23:05:12pjenveysetstatus: open -> closed
resolution: invalid
messages: + msg5603
nosy: + pjenvey
2010-03-28 21:33:00pekka.klarcksetnosy: + pekka.klarck
messages: + msg5602
2010-03-28 20:48:46AndreasEKcreate