Select to view content in your preferred language

Query for Service Definition

221
1
11-21-2024 08:02 AM
kapalczynski
Frequent Contributor

I am attempting to query for a service definition and getting list index out of range errors... not sure why.

Is it because it cant read it... the Service Definition is shared publicly so should not be permissions... 

Any thoughts

 

 

sd_fs_name = "NeighborhoodUtilityPermits"
portal = "https://www.arcgis.com"
user = "username" # username that has permissions to the Feature Layer

sdItem = gis.content.search(query="title:"+ sd_fs_name + " AND owner: " + user, item_type="Service Definition")[0]

 


Search for original SD on portal…
Traceback (most recent call last):
File "C:\Users\Desktop\Portal_to_AGOL_Processing\ProcessingtoAGOL\AGOL_Module.py", line 96, in <module>
sdItem = gis.content.search(query="title:"+ sd_fs_name + " AND owner: " + user, item_type="Service Definition")[0]
IndexError: list index out of range

 

0 Kudos
1 Reply
CodyPatterson
MVP Regular Contributor

Hey @kapalczynski 

If you remove the [0] is the GIS search returning an empty list, or a list at all? You may try print(type(sdItem)) to see if it's returning a certain type that isn't a list.

If it isn't returning anything in the list or is an empty list, check your content.search to be sure it's querying correctly.

Cody

0 Kudos