Hi all.
I've got some code (below) to list the layers in all web mappers.
It works fine when just listing the Title of the layers, but when I had a parameter to print the layer.url as well as the layer title:
"print('\t',l,layer.title)
I get the following error:
This occurs when trying to get the URL for a third party, public WMTS layer, in the Web Map.
Can I modify the code to ignore this error, or list something.
from arcgis.gis import GIS
from arcgis.mapping import WebMap
import arcpy
gis = GIS("pro")
# Search for web maps based on the query. Set max_items to -1 for all maps
webmaps_contents = gis.content.search("*",item_type="Web Map", max_items=500)
print('Number of Web Maps found: ' + str((len(webmaps_contents))))
n=0
#create web map objects from search results and print the web map title and layer name
for webmap_item in webmaps_contents:
if webmap_item.content_status != "deprecated": # Optional to include
n=n+1
print(n,webmap_item.title,webmap_item.content_status)
webmap_obj = WebMap(webmap_item)
l=0
for layer in webmap_obj.layers:
l=l+1
print('\t',l,layer.title)
print("Finished")
Solved! Go to Solution.
You can use Python try/except statements to handle the error gracefully and continue with code execution.
It looks like the URL property is specific to certain kinds of items. Maybe try item.homepage
You can use Python try/except statements to handle the error gracefully and continue with code execution.