ArcPy Project failing as GP Service

1503
17
Jump to solution
01-07-2021 12:50 PM
BrianLeroux
Regular Contributor

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.

 

  • esriJobMessageTypeError: Traceback (most recent call last): File "<string>", line 156, in execute File "<string>", line 441, in getMessages File "d:\program files\arcgis\server\framework\runtime\arcgis\Resources\arcpy\arcpy\management.py", line 11492, in Project raise e File "d:\program files\arcgis\server\framework\runtime\arcgis\Resources\arcpy\arcpy\management.py", line 11489, in Project retval = convertArcObjectToPythonObject(gp.Project_management(*gp_fixargs((in_dataset, out_dataset, out_coor_system, transform_method, in_coor_system, preserve_shape, max_deviation, vertical), True))) File "d:\program files\arcgis\server\framework\runtime\arcgis\Resources\arcpy\arcpy\geoprocessing\_base.py", line 511, in <lambda> return lambda *args: val(*gp_fixargs(args, True)) arcgisscripting.ExecuteError: ERROR 000208: Error creating output feature class Failed to execute (Project).
# 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)[0]
        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)

 

1 Solution

Accepted Solutions
DavidPike
MVP Frequent Contributor

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.

View solution in original post

17 Replies
BlakeTerhune
MVP Regular Contributor

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.

BrianLeroux
Regular Contributor

It is working fine in ArcGIS Pro though. Is the incompatibility only on arcpy available on the ArcGIS server?

BlakeTerhune
MVP Regular Contributor

Try setting the output location for project to a known folder location that exists on the server instead of script_path

BrianLeroux
Regular Contributor

script_path is currently being set as sys.path[0] 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.

DanPatterson
MVP Esteemed Contributor

Project (Data Management)—ArcGIS Pro | Documentation

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

ArcGIS Server documentation—ArcGIS Server | Documentation for ArcGIS Enterprise


... sort of retired...
BrianLeroux
Regular Contributor

The output is not being written to in_memory. It is being output as shapefile.

JoshuaBixby
MVP Esteemed Contributor

The error

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.

BrianLeroux
Regular Contributor

script_path is set using sys.path[0]

DanPatterson
MVP Esteemed Contributor

Have you confirmed with print statements that it isn't attempting to overwrite an existing file without you setting arcpy.env.overwriteOutput = True somewhere?


... sort of retired...