Convert exception to string in Python 2.7
Question: 
    import httplib
    
    webservice = httplib.HTTPSConnection(host)
    # ....
    try:
        webservice.endheaders()
    except Exception, exc:
        handle_failure(request, exc_str=unicode(exc))
    

The exception contains:

> error(110, 'Die Wartezeit f\xc3\xbcr die Verbindung ist abgelaufen')

Don't ask me why this message is in German.

The `uncode(exc)` fails like this:

    
    
    UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 27:
                         ordinal not in range(128)
    

What is the failsafe way to convert an exception to a string in Python 2.7?

Definition of failsafe in this context: I must not get a UnicodeError. The
expection goes to the logs. It is ok if non-ascii characters get lost.


Answer: Add `errors='replace'` or `errors='ignore'` parameter to the `unicode`
function.

The following text is from
[this](https://docs.python.org/2/howto/unicode.html#the-unicode-type)
documentation:

> The `errors` argument specifies the response when the input string can’t be
> converted according to the encoding’s rules. Legal values for this argument
> are ‘strict’ (raise a `UnicodeDecodeError` exception), ‘replace’ (add
> U+FFFD, ‘REPLACEMENT CHARACTER’), or ‘ignore’ (just leave the character out
> of the Unicode result). The following examples show the differences:
>  
>  
>     $ unicode('\x80abc', errors='strict')  
>     Traceback (most recent call last):
>     ...
>     UnicodeDecodeError: 'ascii' codec can't decode byte 0x80 in position 0:
>     ordinal not in range(128)
>     $ unicode('\x80abc', errors='replace')
>     u'\ufffdabc'
>     $ unicode('\x80abc', errors='ignore')
>     u'abc'
>  

