The group property of the arcgis.gis.User class does not retrieve the list of Group objects the current user belongs to if the user is a member of at least one group owned by someone outside the organization, and the 'Who can view this group?' setting is set to 'Only group members' or 'All organization members' in ArcGIS API for Python.
This issue is not reproducible in ArcGIS Online. If the issue occurs, please contact Esri Support Services as additional information is required for further investigation.
解决办法
An administrator can view all the groups a member of the organization is in, both internal and external, from the ArcGIS Online user interface, regardless of the 'Who can view this group?' setting of the group.
Replace user.groups withuser.__dict__['groups'] as an alternative means of retrieving a list of Group objects.