Hello,
I am running a python script below to test/troubleshoot updating a feature service using an UpdateCursor. It works fine in IDLE with ArcGIS Pro but fails in IDLE with ArcGIS Server. I believe Pro 2.9.0 and Server 10.9.1 are supposed to be consistent releases. Both are installed on the same server that the script is run on.
The point of this test is that a shared web tool on the server is failing due to this problem.
import sys, os, arcpy
from arcpy import env
def printMessage(message):
arcpy.AddMessage(message)
print(message)
landParcelsLayer = 'https://server.domain.com/arcgis/rest/services/ParcelsBranchVersioned/FeatureServer/0'
selectFields = ['Field1', 'Field2'.... etc...]
versionToUpdate = 'username@DOMAIN.Edits'
printMessage("Connecting to the edits version...")
printMessage("Using " + landParcelsLayer)
temporaryConnectionFile = arcpy.CreateScratchName(
"", ".lyrx", "", env.scratchFolder)
arcpy.MakeFeatureLayer_management(landParcelsLayer, 'landParcels')
printMessage("Switching to version" + versionToUpdate)
arcpy.ChangeVersion_management('landParcels', 'Branch', versionToUpdate)
arcpy.SaveToLayerFile_management('landParcels', temporaryConnectionFile)
printMessage("Saving " + temporaryConnectionFile)
printMessage("Updating land parcels...")
printMessage("Using: " + temporaryConnectionFile)
printMessage("Using: " + str(selectFields))
i = 0
with arcpy.da.UpdateCursor(temporaryConnectionFile, selectFields) as landParcelsCursor:
for landParcel in landParcelsCursor:
key = landParcel[0]
i = i + 1
if (i > 200):
printMessage(key)
printMessage(landParcel[1])
printMessage(landParcel[2])
if (landParcel[2] == '10-03'):
landParcel[2] = '10-04'
else:
landParcel[2] = '10-03'
landParcelsCursor.updateRow(landParcel)
break
Both python sessions, Pro and Server, begin with the following
Python 3.7.11 [MSC v.1927 64 bit (AMD64)] on win32
The error I get when running the script in IDLE (ArcGIS Server) is below:
landParcelsCursor.updateRow(landParcel)
RuntimeError: ERROR: code:500, Unable to complete operation., GraphicFeatureServer:PerformEdit() returned no result., Internal server error.
When I dive into the server logs for the service the interaction looks identical for both scripts. It's just that one succeeds and one fails.
UPDATE:
There is a difference in the server logs between the 2 sets of requests. The script that runs under ArcGIS Pro authenticates successfully as my Windows AD logged in user. The script that runs under ArcGIS Server is anonymous. So how do I get python scripts under ArcGIS Server to authenticate to a feature service when I use an UpdateCursor?
Any ideas what is going wrong here or how to workaround the issue?