Wo wir gerade beim Thema sind.
Was tun wenn eine Exception mit Unicode gefüttert wurde?
Code: Alles auswählen
In [31]: try: raise Exception(u"müll")
....: except Exception, e: s = str(e)
....:
<type 'exceptions.UnicodeEncodeError'>: 'ascii' codec can't encode character u'\xfc' in position 1: ordinal not in range
(128)
Welche Informationen sind aus .args zugesichert?
Code: Alles auswählen
In [32]: try: raise Exception(u"müll")
....: except Exception, e: s = " ".join(e.args)
....:
In [33]: s
Out[33]: u'm\xfcll'
Das Modul Socket füllt die args auch wieder anders:
Code: Alles auswählen
In [39]: try: socket.socket(101010)
....: except Exception, e: pass
....:
In [40]: e.args
Out[40]: (10047, 'Address family not supported')
Am besten klappt's IMHO mit traceback.format_exc()
Obwohl auch da unicode Objekte mit non-ascii chars als <not printable > ausgegeben werden. Aber es gibt zumindest keine neue Exception bei der Behandlung