PROBLEM
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'
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)
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
Get help from ArcGIS experts
Download the Esri Support App