I am using ArcGIS Python Notebooks on AGOL to summarize some stats regarding groups in our organization and I am getting the following error message:
You do not have permissions to access this resource or perform this operation. (Error Code: 403) Here is the code: import pandas as pd cols=['Group ID','Group Name','Number of Users','Creator Licenses','Other Licenses'] df = pd.DataFrame(columns=cols) groups=gis.groups.search() i=0 for group in groups: item={} print(group) response = group.get_members() num_users=0 creator_num=0 noncreator_num=0 num_items=0 num_maps=0 num_forms=0 #() num_tpk=0 #() num_wms=0 #() num_dashboard=0 #() num_webapp=0 #() num_sm=0 #() for group_items in group.content(max_items=10000000): num_items=num_items+1 item_type=group_items.type if (item_type=='Web Map'): num_maps=num_maps+1 if (item_type=='Form'): num_forms=num_forms+1 if (item_type=='Tile Package'): num_tpk=num_tpk+1 if (item_type=='Map Service'): num_wms=num_wms+1 if (item_type=='Map ServiceDashboard'): num_dashboard=num_dashboard+1 if (item_type=='Web Mapping Application'): num_webapp=num_webapp+1 if (item_type=='StoryMap'): num_sm=num_sm+1 for user in response['users']: num_users=num_users+1 user_obj=gis.users.get(username=user) print(user_obj) try: user_types=user_obj.user_types() #items=user_obj.items(folder=None, max_items=1000000) if (user_types['name']=='Creator'): creator_num=creator_num+1 else: noncreator_num=noncreator_num+1 item={'Group Name':group.title,'Number of Users':num_users,'Group ID':group.groupid,'Creator Licenses':creator_num,'Other Licenses':noncreator_num,'Number of Items':num_items, 'Number of Web Maps':num_maps,'Number of Forms':num_forms,'Number of Tile Packages':num_tpk,'Number of Map Services':num_wms,'Number of Dashboards':num_dashboard, 'Number of Web Apps':num_webapp,'Number of Story Maps':num_sm} df=df.append(item,ignore_index=True) i=i+1 #print(i) df
The error is showing up when I reach a certain user which happens to be from another organization (our Hub organization) so perhaps this the underlying problem. Is there a way to mitigate this?
Solved! Go to Solution.
arcgis.gis module — arcgis 1.8.2 documentation
According to the ArcGIS Python API doc the user object should have an orgId property (user.orgId) but I haven't been able to get that to work - I'll look into that separately. One option is that you could ignore the error by surrounding the logic in a try/catch like below and printing the error message rather than having the code break because of it:
Let me know if you have anymore questions.
Is the error still happening even with this line commented out? When is the error being called?
#items=user_obj.items(folder=None, max_items=1000000)
I suspect there would be authorisation issues when attempting to grab all the items associated with the external user. Or maybe it's when you try to get the user type of the external user.
The error is happening when I call user_types=user_obj.user_types() so it is related to the user type of the external user. Can I exclude users that are not from my organization when I make this call?
arcgis.gis module — arcgis 1.8.2 documentation
According to the ArcGIS Python API doc the user object should have an orgId property (user.orgId) but I haven't been able to get that to work - I'll look into that separately. One option is that you could ignore the error by surrounding the logic in a try/catch like below and printing the error message rather than having the code break because of it:
Let me know if you have anymore questions.
Thanks - the "try catch" option worked