AnsweredAssumed Answered

addFeature to Feature Server using python

Question asked by ecarson on Jun 22, 2015
Latest reply on Jun 22, 2015 by ecarson



I'm trying to add a feature to a Feature Server using python without any success.


When running the script I get the following error HTTPError: HTTP Error 401: Unauthorized.


The service only requires windows authentication of a user logged into the network, the service does not require a username or password.


How can this be achieved in Python?


My code so far is:


add = [{ "geometry" : {"x" : 20.8,"y" : -115.5},"attributes" : {"COMMENTS" : "Test"}}] 

service_url = r"http://<servername>/ags/rest/services/test/testlyr/FeatureServer/"


params = urllib.urlencode({'f': 'json', 'features': add}) 

req = urllib2.Request("{0}/addFeatures/?".format(service_url, params)) 


response = urllib2.urlopen(req) 

jsonResult = json.load(response) 

print jsonResult