List services in Portal for ArcGIS

2298
11
03-22-2021 08:59 PM
Labels (2)
Dionisiobattad
Occasional Contributor

Hi,

 

I am trying to create a list of all services that we have in our Portal. I have seen this script in ArxcGIS Server Administration (https://enterprise.arcgis.com/en/server/latest/administer/windows/example-write-properties-of-all-se...).

When I run it using our server name, port, and my credentials as administrator, I get this error message:

gaierror: [Errno 11001] getaddrinfo failed

I am using IDLE but do I need to use Python 3 here? We are still using 10.6. Thanks.

0 Kudos
11 Replies
LongDinh
Occasional Contributor II

Hi Dionisiobattad,

The linked to the scripts are written in python 2.x - the print statements do not have parentheses.

The error message you have received is likely a python urllib or https error. Your machine may not have access to the requested url that you sent. Some possible reasons may be that you have to use a proxy to access your url or simply, the request is incorrect. 

Also check that the getToken() returns a token. Try running that separately. the admin/generateToken only works on ArcGIS Server if GET is enabled for tokens which it is often not for security reasons.

Hope this information helps.

0 Kudos
MichaelVolz
Esteemed Contributor

You wrote "Also check that the getToken() returns a token. Try running that separately. the admin/generateToken only works on ArcGIS Server if GET is enabled for tokens which it is often not for security reasons."

Can you please elaborate in more detail how to perform the getToken troubleshooting you have referred to here?

 

0 Kudos
LongDinh
Occasional Contributor II

The function getToken() (near the bottom) can be called by itself. Check that you are receiving a token from ArcGIS Server given your input arguments.

You can create a new script which contains only the getToken() function code block and execute with your desired python environment or paste the function into your python interpreter. 

Something like the below should work given your input arguments.

If you are looking at Portal items and urls specifically, I would suggest looking into the arcgis.gis module which searches on Portal rather than the ArcGIS Server REST Admin API. 

def getToken(username, password, serverName, serverPort):
    # Token URL is typically http://server[:port]/arcgis/admin/generateToken
    tokenURL = "/arcgis/admin/generateToken"
    
    params = urllib.urlencode({'username': username, 'password': password, 'client': 'requestip', 'f': 'json'})
    
    headers = {"Content-type": "application/x-www-form-urlencoded", "Accept": "text/plain"}
    
    # Connect to URL and post parameters
    httpConn = httplib.HTTPConnection(serverName, serverPort)
    httpConn.request("POST", tokenURL, params, headers)
    
    # Read response
    response = httpConn.getresponse()
    if (response.status != 200):
        httpConn.close()
        print "Error while fetching tokens from admin URL. Please check the URL and try again."
        return
    else:
        data = response.read()
        httpConn.close()
        
        # Check that data returned is not an error object
        if not assertJsonSuccess(data):            
            return
        
        # Extract the token from it
        token = json.loads(data)        
        return token['token']      

# Insert your args here
username = 'abc'
password = '***'
serverName = 'https://...com'
serverPort = 1234
token = getToken(username, password, serverName, serverPort)
print (token)

 

0 Kudos
MichaelVolz
Esteemed Contributor

Thanks for the standalone getToken sample.  Unfortunately that script is failing with the same error message.  If I wanted to just use the generateToken call from a web browser with the following inputs how would that relate to the inputs in the python script as they appear different to me?  I see username and password as parameters but I do not see http referer or expiration in the token script.

MichaelVolz_0-1621595969730.png

 

0 Kudos
LongDinh
Occasional Contributor II

Refer to the REST API notes on ways to request tokens here: https://developers.arcgis.com/rest/users-groups-and-items/generate-token.htm 

Try something simpler like this:

import requests

params = {
'username': 'JohnSmith',
'password': '****',
'client': 'requestip',
'f':'json'
}
url = 'https://.../arcgis/admin/generateToken'
r = requests.post(url, data=params)
print (r.json())

If you require a proxy to access your AGS, then add in the proxy parameter to your post request.

0 Kudos
JohnBickmore
New Contributor III

I just fixed a similar problem - i changed all instances of HTTPConnection to HTTPSConnection and script started working

I left httpConn as it was

arahman_mdmajid
New Contributor III

What is your ArcGIS Server version? 

Abdur Rahman
GIS Developer
0 Kudos
JohnBickmore
New Contributor III

we have 10.8.1

0 Kudos
ThomasEdghill
Esri Community Moderator

Starting with ArcGIS Enterprise 10.9, I wanted to share that it is now possible to do this directly through the portal with administrative reports. You are able to run an item report which shows a list of all items in your portal, along with other helpful information. In particular, this is the documentation on the outputs when running item reports: Item fields. Hopefully this helps!