UpdateFeature REST API Python Script Unexpected Error
I am trying to update an ArcGIS Online hosted feature using a python script. I have tried a few examples of using Post methods combined with the Example Usage from the ArcGIS REST API documentation for UpdateFeature(http://resources.arcgis.com/en/help/arcgis-rest-api/index.html#/Update_Features/02r3000000zt000000/) but in each case I get the following error:
{"error":{"code":500,"message":"An unexpected error occurred processing the request.","details":[]}}
I am using a json array of features that successfully updates the feature when manually submitted in the form at http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/SanFrancisco/311Incidents/FeatureServer/0....
Here is the code I use for the requests method:
updateBaseURL = "http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/SanFrancisco/311Incidents/FeatureServer/0..."
updateAttr = [
{
"attributes" : {
"objectid": 12976095,
"address" : "66TH ST and HARRISON ST"
}
}
]
headers = {"Content-type": "application/json", "Accept": "text/plain"}
r = requests.post(updateBaseURL, json=updateAttr,headers=headers)
Here is the code I use for the HTTPConnection method:
updateAttr = [
{
"attributes" : {
"objectid": 12976095,
"address" : "66TH ST and HARRISON ST"
}
}
]
headers = {"Content-type": "application/json", "Accept": "text/plain"}
conn = httplib.HTTPConnection('sampleserver3.arcgisonline.com')
conn.request("POST", "/ArcGIS/rest/services/SanFrancisco/311Incidents/FeatureServer/0/updateFeatures/?f=json", json.dumps(updateAttr), headers)
How Can I make this work?
Solved! Go to Solution.
I would think that something like this would work, but I'm getting a 400 error:
import urllib, urllib2, json updateAttr = [{"attributes" : {"objectid": 12988724, "address" : "1217 2ND AVE some change"}}] service_url = r"http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/SanFrancisco/311Incidents/FeatureServer/0" params = urllib.urlencode({'f': 'json', 'features': updateAttr}) req = urllib2.Request("{0}/updateFeatures/?{1}".format(service_url, params)) response = urllib2.urlopen(req) jsonResult = json.load(response) print jsonResult
{u'error': {u'message': u'Unable to complete operation.', u'code': 400, u'details': [u'Unable to update features']}}
The ObjectID in your example does not seem to exist...
I would think that something like this would work, but I'm getting a 400 error:
import urllib, urllib2, json updateAttr = [{"attributes" : {"objectid": 12988724, "address" : "1217 2ND AVE some change"}}] service_url = r"http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/SanFrancisco/311Incidents/FeatureServer/0" params = urllib.urlencode({'f': 'json', 'features': updateAttr}) req = urllib2.Request("{0}/updateFeatures/?{1}".format(service_url, params)) response = urllib2.urlopen(req) jsonResult = json.load(response) print jsonResult
{u'error': {u'message': u'Unable to complete operation.', u'code': 400, u'details': [u'Unable to update features']}}
The ObjectID in your example does not seem to exist...
I got the following code to work based on your suggestion. Thanks so much. I think the key I was missing was formatting the parameters with "features"
Thanks again.