Hey all,
I am trying to use a very simple python script to add users to a group and am getting stuck. It works successfully with one group but when I add more I get errors. Here is my code:
from arcgis import *
gis = GIS("url", "username", "password")
list1 = ['AdvancedUser', 'DefaultUser']
grouping = gis.groups.search('title: group1')
grouping[0].add_users(list1)
When I try with multiple groups here:
from arcgis import *
gis = GIS("url", "username", "password")
list1 = ['AdvancedUser', 'DefaultUser']
grouping = gis.groups.search('title: group1', 'title: group2')
grouping.add_users(list1)
I get the error:
Traceback (most recent call last):
File "<string>", line 5, in <module>
AttributeError: 'list' object has no attribute 'add_users'
Thank you for any help you can provide.
Solved! Go to Solution.
The results of the search operation is a list or results. When you did:
grouping = gis.groups.search('title: group1')
grouping[0].add_users(list1)
You're using the add_users function of the first (index 0) object in the grouping list.
What you have to do, is then iterate over all the elements on the results list and use the add_users function on each of the objects of the list.
from arcgis import *
gis = GIS("url", "username", "password")
list1 = ['AdvancedUser', 'DefaultUser']
grouping = gis.groups.search('title: group1', 'title: group2')
for grp in grouping:
grp.add_users(list1)
The results of the search operation is a list or results. When you did:
grouping = gis.groups.search('title: group1')
grouping[0].add_users(list1)
You're using the add_users function of the first (index 0) object in the grouping list.
What you have to do, is then iterate over all the elements on the results list and use the add_users function on each of the objects of the list.
from arcgis import *
gis = GIS("url", "username", "password")
list1 = ['AdvancedUser', 'DefaultUser']
grouping = gis.groups.search('title: group1', 'title: group2')
for grp in grouping:
grp.add_users(list1)
Thank you Raul! I was seriously I was overthinking it. This really helps.