List services in Portal for ArcGIS

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



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 (

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
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
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
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):
        print "Error while fetching tokens from admin URL. Please check the URL and try again."
        data =
        # Check that data returned is not an error object
        if not assertJsonSuccess(data):            
        # Extract the token from it
        token = json.loads(data)        
        return token['token']      

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


0 Kudos
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.



0 Kudos
Occasional Contributor II

Refer to the REST API notes on ways to request tokens here: 

Try something simpler like this:

import requests

params = {
'username': 'JohnSmith',
'password': '****',
'client': 'requestip',
url = 'https://.../arcgis/admin/generateToken'
r =, 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
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

Occasional Contributor

What is your ArcGIS Server version? 

Abdur Rahman
GIS Developer
0 Kudos
New Contributor III

we have 10.8.1

0 Kudos
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!