does anyone have an idea, why this Python 3.2 code
try:
raise Exception('X')
except Exception as e:
print("Error {0}".format(str(e)))
works without problem (apart of unicode encoding in windows shell :/), but this
try:
raise Exception('X')
except Exception as e:
print("Error {0}".format(str(e, encoding = 'utf-8')))
throws TypeError: coercing to str: need bytes, bytearray or buffer-like object, Exception found ?
How to convert an Error to a string with custom encoding?
Edit
It does not works either, if there is \u2019 in message:
try:
raise Exception(msg)
except Exception as e:
b = bytes(str(e), encoding = 'utf-8')
print("Error {0}".format(str(b, encoding = 'utf-8')))
But why cannot str() convert an exception internally to bytes?