Select to view content in your preferred language

Python Script succeeds in IDLE(ArcGIS Pro 2.9.0) but fails in IDLE(ArcGIS Server 10.9.1)

Jump to solution
12-11-2023 09:09 AM
New Contributor III


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):

landParcelsLayer = ''
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):
            if (landParcel[2] == '10-03'):
                landParcel[2] = '10-04'
                landParcel[2] = '10-03'




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:

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.


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?

0 Kudos
1 Solution

Accepted Solutions
New Contributor III

In the end I switched over to the ArcGIS API for Python rather than using a Cursor from the arcpy world.

View solution in original post

0 Kudos
3 Replies
Occasional Contributor III

Hi there, I went through a really long saga trying to troubleshoot a script that worked with Pro but not with ArcGIS Server Python.  I went through a service ticket with Esri and it took a lot of back and forth.  After much work, we finally determined that my script didn't work when run with the Server python because it was not connected to the license manager.  Arcpy geoprocessing tools have to be connected to the license manager in order to run, even though you can run basic Python (other than geoprocessing) (I REALLY wish Esri made this fact more evident!! It took untold hours and weeks for us to learn this fact).  In my case, I was trying to run it on a server in our public DMZ, and our license manager is on a server in our internal network, and those cannot connect in the desired way, so it was impossible for the public DMZ server's python to be licensed.  We came up with a workaround to run the script in the internal network and it would copy files to the DMZ server rather than directly working on those files from the DMZ.

Sounds like in your case, you are logging into a portal rather than using a license manager?  I'm not familiar with the intricacies of that.  But I wonder if it could be a similar situation, where somehow ArcGIS Server python has limitations when it comes to certain kinds of connections??  I dunno.  Sorry I don't have an answer.  But I thought I'd share all this in case it happened to be of any use to you or someone else looking at this post.

Good luck!!!

0 Kudos
New Contributor III

So... it does not look like authentication is the issue here.  I added the following lines to the script.  Now in the server logs I see the correct user name authenticated but I still have the same problem.  I wish I knew what JSON was being returned from the API to the python script.

arcpy.SignInToPortal('', 'DOMAIN\\username', 'mypassword')
0 Kudos
New Contributor III

In the end I switched over to the ArcGIS API for Python rather than using a Cursor from the arcpy world.

0 Kudos