[GIS] size limit when adding features to ArcGIS Server programatically using POST

arcgis-rest-apiarcgis-serverpython

I'm inserting new points using the ArcGIS Server REST API addFeatures method – this is working correctly.

However, I'm finding that when the JSON reaches a certain (undefined) threshold the POST fails with a 404. If the JSON is reduced in size the (otherwise identical) POST succeeds.

I can't see any inherent limits in Python's request functionality. Is this a known limitation with the ArcGIS Server REST API, or are there any workarounds?

Below is some code to reproduce the problem, using a sample Esri server so you can test it.

The target field has a width of 60 so it's expected that the insertion will return an error message with a string 1000 characters long. But note that it errors with a 404 when the string is 3000 characters long.

import json, requests

for num in [10, 1000, 3000]:

    # The following works with 10, gives a legitimate error with 1000, and gives a 404 with 3000
    value = "a" * num

    data = [{"attributes": {'address': value}, "geometry": {"x": 0,"y": 0 }}]
    params = {"f": "json","features": json.dumps(data)}
    headers = {'content-type':'application/json','Accept':'application/json'}
    response = requests.post("http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/SanFrancisco/311Incidents/FeatureServer/0/addFeatures", headers=headers, params=params)
    print("With number = " + str(num) + " the response is " + response.text)

Results:

With number = 10 the response is
{"addResults":[{"objectId":18209901,"globalId" :
null,"success":true}]}

With number = 1000 the response is
{"error":{"code":400,"message":"Unable to complete
operation.","details":["Unable to add features"]}}

With number = 3000 the response is 404 – File or directory not found.

Why does posting the long JSON string return a 404, and how can this be resolved?

Best Answer

SampleServer3 = ArcGIS 10.0.

SampleServer6 = 10.3.

As suggested, its the server which is having problems, not your code. The following works against 10.3 - note I modified your code to use built-ins instead of Requests. (Remember, Server underwent massive changes between 10.0 and 10.1. If you're stuck at 10.0 I'd suggest looking to upgrade as soon as possible. You can see here that 10.0 has been retired)

import json
import urllib
import urllib2

#url = "http://sampleserver3.arcgisonline.com/ArcGIS/rest/services/SanFrancisco/311Incidents/FeatureServer/0/addFeatures"
url = "http://sampleserver6.arcgisonline.com/arcgis/rest/services/SF311/FeatureServer/1/addFeatures"
headers = {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'}

for num in [10, 1000, 3000]:

    value = "a" * num
    data = [{"attributes": {'address': value}, "geometry": {"x": 0,"y": 0 }}]
    params = {"f": "json","features": data}

    req = urllib2.Request(url, urllib.urlencode(params).encode('UTF-8'), headers)
    response = urllib2.urlopen(req).read()
    response_text = response.decode('UTF-8')
    response_json = json.loads(response_text)
    print response_json

{u'addResults': [{u'success': True, u'objectId': 29413}]}

{u'addResults': [{u'success': True, u'objectId': 29414}]}

{u'addResults': [{u'success': True, u'objectId': 29415}]}

Related Question