Select to view content in your preferred language

Listing layers in Web Map Error

403
2
Jump to solution
01-10-2024 03:52 PM
Kalu_Ribush
New Contributor II

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:

Kalu_Ribush_0-1704929168029.png

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")

0 Kudos
1 Solution

Accepted Solutions
Clubdebambos
Occasional Contributor III

You can use Python try/except statements to handle the error gracefully and continue with code execution. 

~ learn.finaldraftmapping.com

View solution in original post

2 Replies
Dan_Brumm
Occasional Contributor II

It looks like the URL property is specific to certain kinds of items. Maybe try item.homepage

Daniel Brumm
GIS Nerd
0 Kudos
Clubdebambos
Occasional Contributor III

You can use Python try/except statements to handle the error gracefully and continue with code execution. 

~ learn.finaldraftmapping.com