AnsweredAssumed Answered

Access secured Feature Service

Question asked by meghan.kulkarni_Superion on Dec 12, 2018
Latest reply on Jan 4, 2019 by meghan.kulkarni_Superion

Hello,

 

I'm using below code to access FeatureService published using ArcGIS Server. REST endpoint is access protected.

 

import urllib, httplib
def getToken(username, password, serverName, serverPort):
    # Token URL is typically http://server[:port]/arcgis/admin/generateToken
    tokenURL = "/arcgis/tokens/generateToken"

    # URL-encode the token parameters:-
    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 fetch tokens from admin URL. Please check the URL and try again."
        return
    else:
        data = response.read()
        httpConn.close()
          
        # Extract the token from it
        token = json.loads(data)       
        return token['token']

if __name__ == '__main__':
    token = getToken('<username>','<password>','<host>','6443')
    print token

 

I get below error:

 

socket.error: [Errno 10060] A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

 

I'm able to access this Feature Service if I put this URL in a browser and enter the username, password. 

 

Am I missing something in the above code?

 

My Best,

Meghan Kulkarni 

Outcomes