I have a public REST service that has several layers and feature classes that I want to access. According to the documentation. Once I have the arcgis package imported, I can inject my outside REST service as such: *Note: I am using the Jupyter Notebook to test this code.

from arcgis.gis import GIS
gis = GIS("https://hazards.fema.gov/gis/nfhl/rest/services/CSLF/Prelim_CSLF/MapServer")

Since this is a public service, I didn't have to include any username or password parameters. The service has several layers (item_type="Feature Layer) that I want to access; namely Special Flood Hazard Area Change layer, but perhaps others: enter image description here

Using the example from the API docs, I tried to do a search in the service just to see all the layers and any info I might need in future calls. I am using the '.search' method from the content manager.

# search and list all feature layers in my contents
search_result = gis.content.search(query="", item_type="Feature Layer") 

Every time I try this, I get an either a KeyError='num' or a TypeError: must be str, not int (if I try to add a query). What am I doing wrong here and what is the proper way to search within this REST service?

enter image description here

1 Answer 1


This answer actually came from someone on GeoNet but I wanted to post it here in case someone else runs into this problem. In a nutshell, the mod GIS was designed for use with an arcGIS Online account, Portal, or ArcGIS Enterprise Server, not an outside service.

"According to API Reference for the ArcGIS API for Python — arcgis 1.4.2 documentation, a GIS object "is representative of a single ArcGIS Online organization or an ArcGIS Enterprise deployment," and the "constructor constructs a GIS object given a url and user credentials to ArcGIS Online or an ArcGIS Enterprise Portal." The service you reference is not part of ArcGIS Online or an ArcGIS Enterprise Portal, it is a map service published from an unfederated ArcGIS Server.

If you are interested in accessing the properties of an individual map service, you can use the arcgis.mapping module — arcgis 1.4.2 documentation"


from arcgis.mapping import MapImageLayer
mil = MapImageLayer(r"https://hazards.fema.gov/gis/nfhl/rest/services/CSLF/Prelim_CSLF/MapServer")
for lyr in mil.layers:
  print(lyr.properties["name"], lyr.properties["type"])

This answer also worked well. Hope this helps someone with similar issues.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.