Enterprise v10.9.1 (federated)
ArcPro 2.9.7
Python 3.x
For some reason when submitting requests to a feature service's applyEdits task, it doesn't like the updates payload when executed from a .py script source. However, if I print that payload and copy./paste it into the feature service's REST endpoint interface it successfully applies the update.
Sample:
{'f': 'json', 'updates': [{'attributes': {'OBJECTID': 493680, 'REVIEW_STATUS': 'REVIEW', 'PERMIT_ID': '', 'PERMIT_TYPE': 'ERP', 'PERMIT_SUBTYPE': 'IND', 'PROJECT_NAME': 'GROVE LAND', 'APP_NO': '509-107', 'PERMIT_NO': '', 'geometry': {'rings': [[[850428.7066254951, 1107318.8247719035], [851334.0043555796, 1107319.7210955694], [851357.1526032463, 1106852.254182741], [850441.3657209128, 1106858.234485738], [850428.7066254951, 1107318.8247719035]]]}}], 'token': 'validTokenAppendedHere'}
Again, copying pasting the above into the REST endpoint updates parameter input works. However, when executed from the python script it fails with error message:
Solved! Go to Solution.
The applyEdits wants the updates parameter array to be in quotes.
From:
updates.append(dict)
params = {'f': 'json','updates': updates,'token': tok}
To:
updates.append(dict)
params = {'f': 'json','updates': '{}'.format(updates),'token': tok}
Can you post your python code that sends the applyEdits to the service?
Thanks for taking a look!
def getGeometry(oid, url):
params = {'f': 'json',
'objectIds': oid,
'outFields': '*',
'returnGeometry': 'true',
'token': tok}
r = requests.post("{}/query".format(url), data = params, verify=False)
response = json.loads(r.content)
if r.status_code==200:
appCount = (response['features'])
if len(appCount) > 0:
return response
else:
return 0
else:
return 0
def update_egisScratch(oid):
try:
updates = []
dict = {'attributes' : {
'OBJECTID' : oid,
'REVIEW_STATUS' : inputStatus,
'PERMIT_ID': inputPermitId,
'PERMIT_TYPE': inputPermitType,
'PERMIT_SUBTYPE': inputPermitSubType,
'PROJECT_NAME': inputProjectName,
'APP_NO': inputAppId,
'PERMIT_NO': inputPermitId,
'APP_ID': inputAppId}
}
jsonResult = getGeometry(oid, queryURL_egisSCRATCH)
#get the geometry from the getGeometry() function for our new payload
geom = jsonResult['features'][0]['geometry']
dict.update({'geometry': geom})
if not jsonResult == 0:
updates.append(dict)
params = {'f': 'json',
'updates': updates,
'token': tok}
url = "{}/applyEdits".format(queryURL_egisSCRATCH)
print (params)
r = requests.post(url, data=params, verify=False)
response = json.loads(r.content)
print (response)
The applyEdits wants the updates parameter array to be in quotes.
From:
updates.append(dict)
params = {'f': 'json','updates': updates,'token': tok}
To:
updates.append(dict)
params = {'f': 'json','updates': '{}'.format(updates),'token': tok}