Get the error number from an exception

def errno_from_exception(self, ex):
        """
        Get the error number from an exception
        """
        if hasattr(ex, 'errno'):
            return ex.errno
        elif ex.args:
            return ex.args[0]
        else:
            return None