AnsweredAssumed Answered

Accessing ArcGIS Online REST Services through a proxy with Python

Question asked by trillevine on Sep 4, 2014
Latest reply on May 23, 2016 by gisbert61


Hello All,

 

I'm trying to run a script to access an ArcGIS Online REST web service and am behind an orginizational firewall, so I need to go over an authenticated proxy. My understanding is that urllib2 is supposed to pull the proxy settings from my system automatically so I shouldn't need to add any code dealing with that, but I keep getting a socket timeout error (60010) right after the script attempts to establish a connection -- I think this has to do with the proxy, but maybe I'm wrong.  Has anyone else run into this problem and found a sollution?  I tried importing the'socket' module and setting the timout value to 'NONE', as well as setting the expiration to a larger value, but the error keeps appearing after 1 minute.  I've attached the part of my code dealing with the connection to the service -- does anyone out there have any ideas?  Any feedback would be highly appreciated!

 

 

socket.PNG

 

import json, urllib, urllib2 import sys, os import arcpy import shutil  class GetToken(object):     # find feature service attachments, send to directory     def urlopen(self, url, data=None):         # open url, send response         referer = "http://www.arcgis.com/arcgis/rest"         req = urllib2.Request(url)         req.add_header('Referer', referer)         if data:             response = urllib2.urlopen(req, data)         else:             response = urllib2.urlopen(req)         return response     def gentoken(self, username, password,         referer = 'www.arcgis.com', expiration=60):         # gets token from referrer         query_dict = {'username': username,             'password': password,             'expiration': str(expiration),             'client': 'referer',             'referer': referer,             'f': 'json'}         query_string = urllib.urlencode(query_dict)         token_url = "https://www.arcgis.com/sharing/rest/generateToken"         token_response = urllib.urlopen(token_url, query_string)         token = json.loads(token_response.read())         if "token" not in token:             print token['messages']             exit()         else:             return token['token']

Outcomes