Get a Specific Server from an arcgis.gis.server.ServerManager

187
4
Jump to solution
01-26-2021 07:19 PM
NathanHeick1
Occasional Contributor II

I'm trying to learn the ArcGIS API for Python and get used to this pattern of iterating over lists to get the resource you want.  I just don't see in the documentation how you would use the list method to list the servers from a ServerManager object and select one of them specifically.  If I had multiple servers, how would I use the URL to select a server from the list.  I don't like the answer just list them in a Jupyter notebook and choose which one you need.  I'm going to be putting this in a script and I also don't like the idea of just hardcoding the index either.  I don't trust that the order will always be the same in the future.

I can see all the arguments for the class constructor, but I don't see much in general for class attributes.

Reply
0 Kudos
1 Solution

Accepted Solutions
MinbinJiang
Esri Contributor

did you consider to pass in the server URL you're after to select out the server, e.g: 

def get_server(url)
    portal_url="https://spt.gis.com/arcgis"
    portal_username="portaladmin"
    portal_password="adminpassword"
    gis = GIS(portal_url, portal_username, portal_password,verify_cert=False)

    my_servers =gis.admin.servers.list()
    for server in my_servers: 
        print(server.url)
    
        if server.url==url:
            print("hi,we're here")

 

View solution in original post

4 Replies
MinbinJiang
Esri Contributor

did you consider to pass in the server URL you're after to select out the server, e.g: 

def get_server(url)
    portal_url="https://spt.gis.com/arcgis"
    portal_username="portaladmin"
    portal_password="adminpassword"
    gis = GIS(portal_url, portal_username, portal_password,verify_cert=False)

    my_servers =gis.admin.servers.list()
    for server in my_servers: 
        print(server.url)
    
        if server.url==url:
            print("hi,we're here")

 

View solution in original post

NathanHeick1
Occasional Contributor II

Yes, I was thinking of that but the documentation only shows constructor arguments, not available properties.  I printed the __dict__ property of the Server objects and _url was listed, but I did not want to use a private variable.  I do see how url is a property if you just try to access it.  It would be nice if the documentation was more thorough like the JavaScript API.  I prefer having the public attributes described.

Reply
0 Kudos
MinbinJiang
Esri Contributor

I normally will use **dir(object)** rather than __dict__

NathanHeick1
Occasional Contributor II

Thanks, I will add that one to my toolbox.  I can see the url attribute now.

Reply
0 Kudos