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.
Any chance that could be fixed?
Has anyone found a workaround for this? I can confirm that [server].content.folders and [server].services both throw KeyErrors when run against Server 11.2, however, they appear to work against older Server 10.7. Here, the server object is a standalone server.
I am able to reproduce the problem in version 2.2.0.2 of the Python API with the following code. I have replaced my server's fully-qualified domain name with "www.example.net".
from arcgis.gis import serverimport getpassserver_base_url = "https://www.example.net:6443"username=input("What is your AGS username?")password = getpass.getpass(prompt=f"What is your ArcGIS Server password at {server_base_url}?")result = server.Server(url=server_base_url, username=username, password=password, all_ssl=True, initialize=True)result.contentresult.content.folders
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?
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<SPAN class="punctuation token">.</SPAN>services<SPAN class="punctuation token">.</SPAN>list<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># to get list of services in root</SPAN> server1<SPAN class="punctuation token">.</SPAN>services<SPAN class="punctuation token">.</SPAN>folders <SPAN class="comment token"># to get list of folders</SPAN> server1<SPAN class="punctuation token">.</SPAN>services<SPAN class="punctuation token">.</SPAN>list<SPAN class="punctuation token">(</SPAN>folder<SPAN class="operator token">=</SPAN><SPAN class="string token">'System'</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="comment token"># to get services in a particular folder</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
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 <SPAN class="operator token">=</SPAN> <SPAN class="string token"><SPAN>"</SPAN><A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=https%3A%2F%2F" target="_blank">https://</A><SPAN><servername>.spokanecounty.org:6443/arcgis/admin/"</SPAN></SPAN> servDirectory <SPAN class="operator token">=</SPAN> server<SPAN class="punctuation token">.</SPAN>catalog<SPAN class="punctuation token">.</SPAN>ServicesDirectory<SPAN class="punctuation token">(</SPAN>url<SPAN class="punctuation token">,</SPAN><SPAN class="operator token"><</SPAN>User<SPAN class="operator token">></SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="operator token"><</SPAN>Pw<SPAN class="operator token">></SPAN><SPAN class="punctuation token">)</SPAN> servDirectory<SPAN class="punctuation token">.</SPAN>folders <SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
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'
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
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.
Les membres connectés peuvent publier, suivre les mises à jour, et plus encore. Nouveau ici ? Inscrivez-vous gratuitement.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.