"You do not have permissions to access this resource or perform this operation error 403" when I am the owner of the layer

230
1
03-27-2024 01:03 PM
AFackler_NAPSG
Occasional Contributor

Hey all, I am trying to create a notebook that will look at how layers are shared in a few webmaps and (later down the line) send me a message when things are throwing errors or not shared properly. However, I am running into the 403 error saying "You do not have permissions to access this resource or perform this operation" even though I both own the layer and am an admin for my AGOL organization. Any ideas on what could be causing this? Just making a try/except to skip it isn't an option for that I need the script to do in the end.

from arcgis.gis import GIS
import datetime as dt
import time
from arcgis.gis import GIS
from arcgis.mapping import WebMap
gis = GIS('home')

intelmanagerMap = gis.content.get("904575e13cf04ebfb9bdfc4ee0f48cbb")
wm=WebMap(intelmanagerMap)
for lyr in wm.layers:
    try:
        lyr_item = gis.content.get(lyr.itemId)
        print(f"{lyr_item.title} shared with {lyr_item.shared_with}\n")
    except Exception as e:
        print(f"Something is wrong with {lyr.title}. Exception thrown: {e}\n")

output:

SARCOP Tasks v1 - debd1c shared with {'everyone': True, 'org': True, 'groups': []}

ee24a9 Sandbox v9 SIFS Intel Manager 1.0 View shared with {'everyone': True, 'org': True, 'groups': [<Group title:"SARCOP Sandbox v9 - 38f775" owner:afackler_napsg>]}

ee24a9 Sandbox v9 SIFS Intel Manager 1.0 View shared with {'everyone': True, 'org': True, 'groups': [<Group title:"SARCOP Sandbox v9 - 38f775" owner:afackler_napsg>]}

Something is wrong with Waypoint Triage Status View. Exception thrown: You do not have permissions to access this resource or perform this operation.
(Error Code: 403)

Something is wrong with Waypoint Search Type. Exception thrown: You do not have permissions to access this resource or perform this operation.
(Error Code: 403)

UAS Recon Photos Sandbox shared with {'everyone': True, 'org': True, 'groups': []}
0 Kudos
1 Reply
ChristopherCounsell
MVP Regular Contributor

If the item was shared publicly and added as an item to another organization's group, you might not have permission to access it.

e.g. I found one of your items and added it to one of my private groups successfully (later removed it):

d8dde8a53c1b481abf4ebc89d15b769f

See here for more conversation:

https://github.com/Esri/arcgis-python-api/issues/1224

There used to be a defect was well with identifying groups that have external users or parnered groups (BUG-000145104) but I believe that may have been resolved. For these groups and your issue you can add a try/except statemtn to go through the groups one by one, listing the groups, and identifying any moments that you have permissions errors with. Then for those layers you can further investigate;

for group in lyr_item.shared_with['groups']:
    try:
        # do whatever with the group
        print((group.title, group.owner, group.access))
    except Exception:
        print('... no permissions to this group')
0 Kudos