def clean_error ( err ) : if err : decoded = err . decode ( 'utf-8' ) try : return decoded . split ( '\r\n' ) [ - 2 ] except Exception : return decoded return 'There was an error.'
how to access the message in attributeerror python
Take stderr bytes returned from MicroPython and attempt to create a non - verbose error message .
def clean_error(err):
    """
    Take stderr bytes returned from MicroPython and attempt to create a
    non-verbose error message.
    """
    if err:
        decoded = err.decode('utf-8')
        try:
            return decoded.split('\r\n')[-2]
        except Exception:
            return decoded
    return 'There was an error.'