I have an python tool that runs fine in ArcGIS pro. I was able to publish as a service to my ArcGIS Enterprise however when I try to run the service it gives an error. It looks like the it is hung up when trying to call arcpy.Project_management. Any ideas on why this would run fine in Pro but not as a GP service? Thanks in advance.
# what to do with a polygon logging.debug( "Input feature is a polygon based on config, buffer will not be created") poly = arcpy.AsShape(feature["geometry"], True) try: wkid = feature["geometry"]["spatialReference"]["latestWkid"] except Exception: wkid = feature["geometry"]["spatialReference"]["wkid"] pass in_sr = arcpy.SpatialReference(wkid) poly_fc = arcpy.CreateFeatureclass_management( "in_memory", "tempPoly", "POLYGON", spatial_reference=in_sr) logging.debug("Spatial Reference of poly_fc: " + arcpy.Describe(poly_fc).spatialReference.name) # Open an insert cursor with arcpy.da.InsertCursor(poly_fc, ["SHAPE@"]) as cursor: # add the poly to the feature class cursor.insertRow([poly]) # reproject the poly feature class to 4326 if it's not already so the # buffer output will be in 4326 and be more accurate if wkid == 4326: event_poly = poly_fc else: projected_poly = os.path.join(script_path,"prjPoly.shp") arcpy.Project_management( poly_fc, projected_poly, arcpy.SpatialReference(4326)) arcpy.CopyFeatures_management(projected_poly, event_poly) arcpy.Delete_management(projected_poly) logging.debug("event Poly feature count: " + str(arcpy.GetCount_management(event_poly).getOutput(0))) logging.debug("event Poly spatial reference: " + arcpy.Describe(event_poly).spatialReference.name)
Solved! Go to Solution.
I'm not sure where your outputs are set to, but if for example the script_path folder is not registered to the server datastore, it will fall over. The error certainly appears to be related to the server being unable to create an output somewhere.
Perhaps share the full code and script tool parameters to get more detailed advice.
Blake is right, as far as I know, Project will only work if output to a physical location, but I'm assuming script_path is a folder which is why it works in desktop. You can however cheat this by specifying a scratch workspace of scratch GDB as the output location. On publishing, Server seems to interpret this and modify the path to its own scratch environment.
I'm pretty sure arcpy.Project_management() is not compatible with in_memory workspace. Maybe while it's running as a GP service it gets run in such a manner and is erroring out.
script_path is currently being set as sys.path which should be a good path. But I should confirm that. I will try loggint his path out before I run the reprojection to ensure the path is valid. I can also try hardcoding the path to see if that helps. That will be good from a troubleshooting perspective but I do not like hardcoding paths so I will have to find a better way if it does work out.
The in_memory workspace is not supported as a location to write the output dataset.
From Pro 2.7 help. If you are using something else other than Pro, then you would have to consult that help. For example
ERROR 000208: Error creating output feature class Failed to execute (Project).
indicates the problem is creating the output from the Project tool. Since you haven't shared how the script_path variable is set, it is difficult to say anything more specific.
Have you confirmed with print statements that it isn't attempting to overwrite an existing file without you setting arcpy.env.overwriteOutput = True somewhere?