Select to view content in your preferred language

Arcpy in Geoprocessing Service

766
5
01-13-2023 08:17 AM
KrisFoster1
Occasional Contributor

I'm currently working on a python script that I will be publishing as a geoprocessing service in ArcGIS Enterprise.  I'm running into an issue with an arcpy function that works when debugging and when executing the script from ArcGIS Pro, but when it is published as a geoprocessing service the arcpy.ListTables() return None.  I've set the arcpy.env.workspace to the same URL of a feature service in all of my testing, but only when it executes from the geoprocessing service does it fail.  Any thoughts what's going on here? Is there certain arcpy functions that don't work in a geoprocessing service?

ArcGIS Enterprise 10.9.1
ArcGIS Pro 2.9.5

Code snippet

KrisFoster1_0-1673626539242.png

And here is the error, failing because arcpy.ListTables is None in the geoprocessing service context

esriJobMessageTypeError: Traceback (most recent call last): File "E:\arcgis\arcgisserver\directories\arcgissystem\arcgisinput\InformationFromSAMS.GPServer\extracted\p20\geoprocessors\Common.py", line 62, in LogMessageInDatabase integrationLoggingTable = FindTable(IntegrationFeatureServiceURL, "IntegrationLogging"); File "E:\arcgis\arcgisserver\directories\arcgissystem\arcgisinput\InformationFromSAMS.GPServer\extracted\p20\geoprocessors\Common.py", line 93, in FindTable for table in tables: TypeError: 'NoneType' object is not iterable

0 Kudos
5 Replies
KrisFoster1
Occasional Contributor

Update.... If I force a sign in to portal it works in the geoprocessing service... Are sign in credentials used to execute the geoprocessing service not passed off to arcpy properly? Am I missing something here? Seems arcpy should have those log in credentials. It gets them in the arcgis pro context.

KrisFoster1_0-1673628177101.png

 

0 Kudos
by Anonymous User
Not applicable

Is the table in Portal shared to everyone (publicly available)? If it's not, then you will have to pass the creds from your script to access it because it's restricted.

0 Kudos
KrisFoster1
Occasional Contributor

It's not shared to everyone.  The script is published as a geoprocessing service and that geoprocessing service is shared the same way as the feature service is.  To be able to execute the geoprocessing service you need to authenticate in the first place, so those credentials should be passed to arcpy (like it is when executed from ArcGIS Pro), but it doesn't appear to be doing that.

0 Kudos
KrisFoster1
Occasional Contributor

Update.... The arcpy.GetSigninToken() does have a token provided to arcpy so the appropriate log in credentials seem to be provided in the geoprocessing service for that portion.  I can at least use that token for direct rest service calls now, but would be ideal to be able to use the other arcpy calls with the appropriate credentials provided.  I tried setting the arcpy.env.workspace to the URL with the token provided, but that line crashed with the token specified.

KrisFoster1_1-1673638245655.png

KrisFoster1_2-1673638317272.png

 

 

 

0 Kudos
by Anonymous User
Not applicable

Nice to see you are making progress. The workspace is more of local folder location or geodatabase from which inputs are taken and outputs are placed when running tools. Url's are invalid.  You could set it to a folder/ gdb on the server, but would that be needed?

0 Kudos