PROBLEM

Unable to retrieve service layers in Portal for ArcGIS using API for Python

Last Published: July 10, 2024

Description

It is possible to identify and list all service layers in Portal for ArcGIS using ArcGIS API for Python with the list() function. However, attempting to obtain the list using the list() function fails and returns the following generic error:

Error: 
AttributeError: 'PropertyMap' instance has no attribute 'layers'
Generic error message returned in the Python console

Cause

The script uses the admin.servers module to obtain the list. When the admin.servers module is used, the returned list is referenced from its admin URL. If the process does not involve any administrative procedure, this is not a recommended workflow. The following is a sample script that may fail and return the error.

from arcgis.gis import GIS
from arcgis.gis.server import Server
from arcgis.features import FeatureLayerCollection

gis = GIS("https://<machine>.<domain>.com/<web_adaptor_name>", "username", "password", verify_cert=False)

gis_servers = gis.admin.servers.list()
server1 = gis_servers[0]
fservices = server1.services.list()

for service in fservices:
        layer = FeatureLayerCollection(service.url, gis)
        print(layer)

Solution or Workaround

The admin.servers.list() function must be replaced with the content.list() function. The content module does not have built-in filtering. This may affect processing time, but it ensures the search operation lists all layers. The following is a sample use of the function based on the script provided above.

server1 = gis_servers[0]
fservices = server1.content.list()

for service in fservices:
        layer = FeatureLayerCollection(service.url, gis)
        print(layer)

The process can be streamlined further by specifying the as_dict parameter within the list() function to True to only retrieve feature services and disregard other types of items. The following sample demonstrates the as_dict parameter set to True.

server1 = gis_servers[0]
fservices = server1.content.list(folder="<folder_name>", as_dict=True)

for service in fservices:
        layer = FeatureLayerCollection(service.url, gis)
        print(layer)

Article ID: 000033032

Software:
  • Portal for ArcGIS
  • ArcGIS Server
  • ArcGIS Enterprise 11 0
  • ArcGIS Enterprise 11 1
  • ArcGIS Enterprise 11 3
  • ArcGIS Enterprise 11 2

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options