Is anyone else having trouble of importing arcgis.gis.server module?

1940
12
02-10-2018 07:26 PM
SpencerHan1
New Contributor II

Following the 1.3 documentation, there is a arcgis.gis.server submodule nested under arcgis.gis. 

However when I try use it, I get an error saying "`arcgis.gis` has no attribute `server`". Souce code as shown below. 

>>> import arcgis

>>> arcgis.gis.server.Server(args)

And as suggested in this post, I tried with importing arcgis.gis. But same error occured. 

>>> from arcgis importgis

>>> gis.server.Server(args)

Any help would be greatly appreciated. 

0 Kudos
12 Replies
JoshuaBixby
MVP Esteemed Contributor

It has to do with Esri's goofy imports within the arcgis modules.  Try:

from arcgis.gis import server
server.Server(...)
SpencerHan1
New Contributor II

Thanks, seems to be working. 

0 Kudos
AndrewChapkowski
Esri Regular Contributor

Spencer and Joshua,

Thank you for your comment/reply on using the Server class.

Here is the best way to access your server:

gis = GIS(url="https://mysite.com/portal", username='*****')
servers = gis.admin.servers.list()

JoshuaBixby
MVP Esteemed Contributor

Andrew, the OP never stated whether the desired connection was to a federated or unfederated server, my guess is the latter.

What's new in version 1.3 | ArcGIS for Developers states:

What's new in version 1.3

New

  • Added support for unfederated ArcGIS Server instances from the arcgis.gis.server module

I can't speak for others, but reading that strongly implies to me that one should use arcgis.gis.server when connecting to an unfederated GIS server.  Furthermore, the documentation for arcgis.gis module — arcgis 1.4.0 documentation doesn't mention anything about connecting to an unfederated GIS server.  I have discovered, through trial and error, that I can use the unfederated server's administrator REST endpoint (/arcgis/admin) to connect using the GIS class.

If the ArcGIS API for Python team wants users to use GIS as the starting point, it would be helpful to clarify and/or expand the documentation to point users in that direction.

PhilLarkin1
Occasional Contributor III

Hi bixb0012

Have you had any luck accessing services this way? Can you post an example? Getting access to an unfederated server is a bewildering process with the ArcGIS Python API.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Phil, are you speaking about accessing services starting from GIS() or gis.server.Server()?

0 Kudos
PhilLarkin1
Occasional Contributor III

gis.server.Server() 
Here is one method I have tried (edited to remove redundant code)

from arcgis.gis import server

url = r"https://<server>.<domain>.org:6443/arcgis/admin/"


srv = server.catalog.ServicesDirectory(url,username="<usr>",password="<pw>")

print(srv.list("<example>"))

...
KeyError: 'folders'‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍
0 Kudos
PhilLarkin1
Occasional Contributor III

My arcgis api is version 1.2.3. An update should solve this problem. 

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

After an update, post back if you are still having problems.  Check out the Upgrade the arcgis package at Install and set up | ArcGIS for Developers 

0 Kudos