Select to view content in your preferred language

Error of python code in ArcGIS Online Notebook

695
3
12-29-2022 07:57 AM
anonymous55
Frequent Contributor

Hello

I am running this code on AGOL Notebook but I am getting error. The code is from Esri website 

https://support.esri.com/en/technical-article/000016853

I don't know why I am getting this error:

anonymous55_0-1672329278824.png

 

Tags (3)
0 Kudos
3 Replies
DanPatterson
MVP Esteemed Contributor

what did you provide for steps 1 and 2 in your link?


... sort of retired...
0 Kudos
anonymous55
Frequent Contributor

This is exact code on blog except I am running it on Notbook on arcgis online. Then I didn't provide password and a portal url just user name

 

import arcgis
from arcgis.gis import GIS

user = "UserName" ##My User name

##for web maps
webmaps = gis.content.search("owner:" + user, item_type="Web Map", max_items=10)
webmaps

##for feature layers 
fcs = gis.content.search("owner:" + user, item_type="Feature Layer", max_items=10)
fcs

##for feature layers
fcs.url
fc_layers = fcs.layers
fc_layers.url

##for web maps
web_map_obj = arcgis.mapping.WebMap(webmaps)
maplayers = web_map_obj['operationalLayers']
maplayers['url']

 

 

0 Kudos
AntoinevanEsch
Esri Contributor

Hi @anonymous55,

Have u tried working with for loops and/or list indexes?

In the example, they probably have only 1 webmap and 1 feature layer. If you have multiple webmaps en feature layers, the result of gis.content.search will be stored as a list.

To extract all feature layer URLs you can for example try:

for i in fcs:
    print(i.url)

It is also possible to work with list indices.

Hope this will help you out.

 

0 Kudos