'folders' key error on ServicesDirectory at ArcGIS API 1.4

1900
8
04-16-2018 03:19 AM
BenHolmes1
New Contributor III

I've been trying to access the REST endpoint using the ArcGIS API for Python 1.4

When using any ServicesDirectory method which mentions folders, I get the key error seen here.

key error in ServicesDirectory

Any chance that could be fixed?

0 Kudos
8 Replies
AndrewChapkowski
Esri Regular Contributor

Ben,

Since I can't see your URLs, I'm going to assume that is the issue.

url = "http://mysite.com/server" # So it's net location / web adapter 
gis = GIS(url="http://mysite.com/portal", username="******", password='*******')
sd = ServicesDirectory(url=url, portal_connection=gis)

Even though this will work, accessing a server this way is not recommended.  You would go through your GIS object instead since your site is federated. 

myservers = gis.admin.servers.list()

It will return an array of server objects.

0 Kudos
BenHolmes1
New Contributor III

Hi Andrew

Thanks for the response.

Sorry for my lack of clarity. The URLs were okay, I just left them out as they are internal.

My objective was to get lists of services in a folder on the server and then gather some further information on them.

I thought the ServicesDirectory.list(folder="abc") method looked like an easy method in the API docs.

But any reference to 'folder' in any ServicesDirectory methods throws an error. That seems to have been around for a few versions.

I did remove the connection through the federated "gis" connection as you suggested though.

Regards

Ben

0 Kudos
PhilLarkin1
Occasional Contributor III

Ben Holmes‌ Have you found a resolution for this? I've experienced it from v1.2.3 - 1.4.1.

Can a group admin respond to this thread? Jay Theodore Atma Mani

What is wrong with this code? 

url = "https://<servername>.spokanecounty.org:6443/arcgis/admin/"
servDirectory = server.catalog.ServicesDirectory(url,<User>,<Pw>)
servDirectory.folders

Results in this traceback:
Traceback (most recent call last):
   File "<string>", line 1, in <module>
   File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\server\catalog.py", line       259, in folders
      return self.properties['folders']
   File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\_impl\common\_mixins.py",    line 340, in __getitem__
      return self._mapping[key]
KeyError: 'folders'

0 Kudos
by Anonymous User
Not applicable

Phil Larkin‌, Ben Holmes‌ since the objective is to get a list of `Service` objects in each folder, please refer to the doc here: Managing your GIS servers | ArcGIS for Developers  In short below should work in version `1.4.1`

server1.services.list()  # to get list of services in root
server1.services.folders # to get list of folders
server1.services.list(folder='System') # to get services in a particular folder
0 Kudos
PhilLarkin1
Occasional Contributor III

Hi Atma, thanks for your reply. 

I'm attempting to access the ServicesReport REST endpoint on a local enterprise server. Using the arcgis.gis.server module offers the ServicesDirectory.report function. It doesn't appear to me that the arcgis.gis.admin module has any applicable functions. Can you tell me how i would use the admin module to get to the ServicesReport end point? 

0 Kudos
PhilLarkin1
Occasional Contributor III

I wasn't able to get the ServicesReport so I iterated over services to get the status/statistics. Thanks for your help Atma Mani‌. Ben Holmes‌ hopefully this helps.

from arcgis.gis import server

url = "https://<servername>.spokanecounty.org:6443/arcgis/admin"
srv = server.Server(url=url, username= <username>, password = <password>)

srvManager = srv.services

for folder in srvManager.folders:
    for service in srv.services.list(folder):
        summary = service.statistics['summary']
        status = service.status

					
				
			
			
				
			
			
				
			
			
			
			
			
			
		
0 Kudos
PhilLarkin1
Occasional Contributor III

This has since broken at AGS 10.7.1 in a shared site configuration. Using API 1.8.1

AttributeError: 'Server' object has no attribute 'services'

 

0 Kudos
by Anonymous User
Not applicable

I experienced the same error and found that the methods and properties of ServicesDirectory didn't work with a url from Server 10.4 was used. BUT It worked with a url from 10.6. Could this be a bug Atma Mani ? Is ArcGIS API for Python only for versions > 10.5?

0 Kudos