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

3879
6
Jump to solution
06-25-2021 08:36 AM
CliveSwan
Occasional Contributor II

Greetings,

I used the ESRI Python code to get a list of Services. URL:arcgis.gis.server module — arcgis 1.8.5 documentation

Using the same code:

gis = GIS(portalURL, username, password) ##print('Connected to {} as {}'.format(gis_name.properties.portalHostname, gis_name.users.me.username)) print("Logged IN") #print(gis.admin.servers.validate()) ### true gis_server = gis.admin.servers.list() print(gis_server) server1 = gis_server[0] services = server1.services.list() print(services)

The server name is returned, throws an error on the following line:

services = server1.services.list()

Error message:

Traceback (most recent call last):
File "C:/Users/tmpgcesn/PycharmProjects/TEST/venv/Test/LOGS_Internal.py", line 31, in
services = server1.services.list()
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\server\_common\_base.py", line 86, in __getattr__
raise AttributeError("'%s' object has no attribute '%s'" % (type(self).__name__, name))
AttributeError: 'Server' object has no attribute 'services'

Process finished with exit code 1

Has anyone resolved this issue?? Or can point to any suggestions?

Regards,

Clive

0Kudos
1 Solution

Accepted Solutions
CliveSwan
Occasional Contributor II

Hi Dan,

Thanks for the message.

I read the link in your message, the answer is:

From ESRI Upgrade to ArcGIS Pro 2.7 - arcgis module 1.8.3.

I have ArcGIS Pro 2.7.2 installed, with arcgis module 1.8.3...

It still doesn't work...

View solution in original post

0Kudos
6 Replies
DanPatterson
MVP Esteemed Contributor

AttributeError: 'ServiceManager' object has no att... - Esri Community

there are a number of similar errors, none of which were answered and it has been going on over several versions...

It was reported and apparently fixed.... go figure

BUG-000136577: When using the services.list() function, the followi.. (esri.com)

You might want to post an "Issue" on their github site

Esri/arcgis-python-api: Documentation and samples for ArcGIS API for Python (github.com)


... sort of retired...
CliveSwan
Occasional Contributor II

Hi Dan,

Thanks for the message.

I read the link in your message, the answer is:

From ESRI Upgrade to ArcGIS Pro 2.7 - arcgis module 1.8.3.

I have ArcGIS Pro 2.7.2 installed, with arcgis module 1.8.3...

It still doesn't work...

0Kudos
DanPatterson
MVP Esteemed Contributor

confused as to why your answer is marked correct then.

perhaps upgrade to Pro 2.8 and arcgis 1.8.5


... sort of retired...
0Kudos
NeilEtheridge
New Contributor III

In my case I was getting this error when 2 of my arcgis server machines federated with the portal were shutdown.

Cheers,

Neil

0Kudos
JoshuaWatson3
New Contributor

I have been able to recreate this issue with versions of the ArcGIS Python API from 1.8.2 to 1.9.1.

For anyone still having this issue, it seems it is caused when using a non-standard Portal Administrator account to connect with. There seems to be a way around by explicitly re-connecting using the 'portal_connection' optional argument as follows:

gis = gis (portal_url, user_name, user_pass) hosting_server_url = gis.admin.servers.get(role="HOSTING_SERVER")[0].url hosting_server = Server(url=hosting_server_url, portal_connection=gis)

For some reason, the Server Object returned from gis.admin.servers.get() is a connection, but not a true Administrative connection. I was able to return the URL, but not many other properties.

Hope this helps someone.

RobertO_Donnell
New Contributor II

For some reason the 2 steps for setting the hosting_server you have didn't work for me. BUT, finally figured out how to get it to work and why the old code doesn't work anymore. I'm at 1.9.1 now.

At some point it changed from being able to use the Server object to having to use the ServerManager for federated sites to get the ability to use the list() on services.

So instead of the old:

gis = gis (portal_url, user_name, user_pass) gis_servers = gis.admin.servers.list() server1 = gis_servers[0]

It changed to

gis = gis (portal_url, user_name, user_pass) server1 = gis.admin.servers.get(role="HOSTING_SERVER")[0] #note, don't use the .url as that is only a url reference versus the object, but definately use the [0] which isn't in the help as otherwise its just a list. And this is the object so you don't need another line to get it.

Finally all my start/stop, response time queries, and other scripts are working again!

References:

https://developers.arcgis.com/python/api-reference/arcgis.gis.server.html#server

https://developers.arcgis.com/python/api-reference/arcgis.gis.server.html#arcgis.gis.server.ServerMa...