Get the message of an exception as a Unicode string.
On Python 3, the exception message is always a Unicode string. On Python 2, the exception message is a bytes string most of the time.
If the exception message is a bytes strings, try to decode it from UTF-8 (superset of ASCII), from the locale encoding, or fallback to decoding it from ISO-8859-1 (which never fails).
New in version 1.6.
already unicode.
incoming – Text’s current encoding
errors – Errors handling policy. See here for valid values http://docs.python.org/2/library/codecs.html
text or a unicode incoming encoded representation of it.
TypeError – If text is not an instance of str
Encodes incoming text/bytes string using encoding.
If incoming is not specified, text is expected to be encoded with current python’s default encoding. (sys.getdefaultencoding)
incoming – Text’s current encoding
encoding – Expected encoding for text (Default UTF-8)
errors – Errors handling policy. See here for valid values http://docs.python.org/2/library/codecs.html
text or a bytestring encoding encoded representation of it.
TypeError – If text is not an instance of str
See also to_utf8() function which is simpler and don’t depend on the locale encoding.
Encode Unicode to UTF-8, return bytes unchanged.
Raise TypeError if text is not a bytes string or a Unicode string.
New in version 3.5.
Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.