Calling map.layers[0] fails

76
1
02-13-2020 03:50 PM
ThomasColson
MVP Frequent Contributor

According to 3D Mode | ArcGIS for Developers 

if I call

world_countries_item = gis.content.get('ac80670eb213440ea5899bbf92a04998')
world_countries_layer = world_countries_item.layers[0] 
world_countries_layer‍‍‍‍‍‍‍‍‍‍‍‍

I should see some output

ops_map = gis.content.get('3fcf74a391804b81bff12d56442f23d5')
ops_map_layer = ops_map.layers[0]

But I get 

Traceback (most recent call last):
 File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\__init__.py", line 6773, in __getitem__
 return dict.__getitem__(self, k)
KeyError: 'layers'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
 File "<string>", line 1, in <module>
 File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\__init__.py", line 6746, in __getattribute__
 if self['layers'] == None or self['layers'] == []:
 File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\__init__.py", line 6777, in __getitem__
 return dict.__getitem__(self, k)
KeyError: 'layers'

This is a real working AGOL map with many layers, so what's going on here? And yes I'm logged as the same owner of the map

0 Kudos
1 Reply
JoshuaBixby
MVP Esteemed Contributor

I just did a quick check/test using your same workflow, and I don't get the error.  What is returned from the item.type property?

0 Kudos