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?
params=params
, which containsjson.dumps(data)
? PS I've updated the code so you can verify this