Api.user.get_users() issues

So I have the docs in front of me: https://docs.plone.org/develop/plone.api/docs/user.html#get-user

So I do exactly as the docs:

In [1]: from plone import api
   ...: users = api.user.get_users()
   ...:
---------------------------------------------------------------------------
CannotGetPortalError                      Traceback (most recent call last)
/opt/plone/zeocluster/parts/client2/bin/interpreter in <module>()
      1 from plone import api
----> 2 users = api.user.get_users()

<decorator-gen-144> in get_users(groupname, group)

/opt/plone/buildout-cache/eggs/plone.api-1.7-py2.7.egg/plone/api/validation.pyc in wrapped(f, *args, **kwargs)
     98                 )
     99
--> 100             return f(*args, **kwargs)
    101
    102         return decorator(wrapped, func)

/opt/plone/buildout-cache/eggs/plone.api-1.7-py2.7.egg/plone/api/user.pyc in get_users(groupname, group)
    164             raise GroupNotFoundError
    165
--> 166     portal_membership = portal.get_tool('portal_membership')
    167
    168     if group:

<decorator-gen-114> in get_tool(name)

/opt/plone/buildout-cache/eggs/plone.api-1.7-py2.7.egg/plone/api/validation.pyc in wrapped(f, *args, **kwargs)
     68                 )
     69
---> 70             return f(*args, **kwargs)
     71
     72         return decorator(wrapped, func)

/opt/plone/buildout-cache/eggs/plone.api-1.7-py2.7.egg/plone/api/portal.pyc in get_tool(name)
    116     """
    117     try:
--> 118         return getToolByName(get(), name)
    119     except AttributeError:
    120

/opt/plone/buildout-cache/eggs/plone.api-1.7-py2.7.egg/plone/api/portal.pyc in get()
     80
     81     raise CannotGetPortalError(
---> 82         'Unable to get the portal object. More info on '
     83         'http://docs.plone.org/develop/plone.api/docs/api/exceptions.html'
     84         '#plone.api.exc.CannotGetPortalError'

CannotGetPortalError: Unable to get the portal object. More info on http://docs.plone.org/develop/plone.api/docs/api/exceptions.html#plone.api.exc.CannotGetPortalError

No problem, I know how to fix that...

In [2]: site = 'intranet'
In [3]: context = app[site]
In [4]: from zope.site.hooks import setSite
In [5]: setSite(context)

Great, let's try that again:

In [6]: users = api.user.get_users()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/opt/plone/zeocluster/parts/client2/bin/interpreter in <module>()
----> 1 users = api.user.get_users()

<decorator-gen-144> in get_users(groupname, group)

/opt/plone/buildout-cache/eggs/plone.api-1.7-py2.7.egg/plone/api/validation.pyc in wrapped(f, *args, **kwargs)
     98                 )
     99
--> 100             return f(*args, **kwargs)
    101
    102         return decorator(wrapped, func)

/opt/plone/buildout-cache/eggs/plone.api-1.7-py2.7.egg/plone/api/user.pyc in get_users(groupname, group)
    169         return group.getGroupMembers()
    170     else:
--> 171         return portal_membership.listMembers()
    172
    173

/opt/plone/buildout-cache/eggs/Products.PlonePAS-5.0.14-py2.7.egg/Products/PlonePAS/tools/membership.pyc in listMembers(self)
    534         several hundred of users :)
    535         '''
--> 536         return BaseTool.listMembers(self)
    537
    538     @security.protected(ManageUsers)

/opt/plone/buildout-cache/eggs/Products.CMFCore-2.2.10-py2.7.egg/Products/CMFCore/MembershipTool.pyc in listMembers(self)
    401         '''Gets the list of all members.
    402         '''
--> 403         return map(self.wrapUser, self.acl_users.getUsers())
    404
    405     security.declareProtected(ListPortalMembers, 'searchMembers')

/opt/plone/buildout-cache/eggs/Products.CMFCore-2.2.10-py2.7.egg/Products/CMFCore/MembershipTool.pyc in wrapUser(self, u, wrap_anon)
    129             # u isn't wrapped at all.  Wrap it in self.acl_users.
    130             b = u
--> 131             u = u.__of__(self.acl_users)
    132         if (b is nobody and not wrap_anon) or hasattr(b, 'getMemberId'):
    133             # This user is either not recognized by acl_users or it is

AttributeError: 'NoneType' object has no attribute '__of__'

Can anyone tell me what's going on and why I cannot get a simple list of users?

I tried that with plone 5.1 and it returned users list in 'users' as described in the docs
My guess is that you have some add-on installed that gets in the way. Probably ldap from the 'hundred of users' part. Possibly Ldap config is not perfect or there is a bug in the implementation you use. But with vanilla Plone this works.

I am using pas.plugings.ldap, it seems like this is the best plugin there is for ldap.
The settings for ldap are correct, and it works well retrieving the users for sharing and other purposes.
I am not that versed in plone, so can someone please explain the last few lines to me? Maybe I can put a temporary fix so at least it doesn't fail.

    b = getattr(u, 'aq_base', None)
    if b is None:
        # u isn't wrapped at all.  Wrap it in self.acl_users.
        b = u
        u = u.__of__(self.acl_users)

If b is None then it makes sense that None is NoneType, no? and of course NoneType has no attribute __of__

it seems that self.acl_users.getUsers() can return at least one element (user) with a None value. If it's true it does not make much sense to me, but I know nothing about this code.
If what you want is a quick and dirty result, you can try to replace
self.acl_users.getUsers()
by
filter(None, self.acl_users.getUsers())
Absolutely no warranty. Please take all precautions before patching your code.