Geographic Information Systems Asked by freshop on March 26, 2021
I have been trying to publish a python ‘Hello, World!’ sample geoprocessing service. I have ArcMap 10.7.1 and ArcGIS Enterprise Server 10.71. In Arc Map I started with a new Python Toolbox, and added an input parameter (string) and output parameter (string). The script will echo the input parameter as the result to show things are set up correctly and working. It works in ArcMap. I can also run the .pyt script on the ArcGIS Server locally.
Here is the complete python tool box:
import arcpy
class Toolbox(object):
def __init__(self):
"""Define the toolbox (the name of the toolbox is the name of the
.pyt file)."""
self.label = "BasicTest"
self.alias = "Tool"
# List of tool classes associated with this toolbox
self.tools = [Tool]
class Tool(object):
def __init__(self):
"""Define the tool (tool name is the name of the class)."""
self.label = "Tool"
self.description = "Desc"
self.canRunInBackground = True
def getParameterInfo(self):
"""Define parameter definitions"""
params = []
params.append(arcpy.Parameter(displayName='Input',
name='Input',
datatype='String',
parameterType="Required",
direction="Input"))
params.append(arcpy.Parameter(displayName='Output',
name='Output',
datatype='String',
parameterType='Derived',
direction='Output'))
return params
def isLicensed(self):
"""Set whether tool is licensed to execute."""
return True
def updateParameters(self, parameters):
"""Modify the values and properties of parameters before internal
validation is performed. This method is called whenever a parameter
has been changed."""
return
def updateMessages(self, parameters):
"""Modify the messages created by internal validation for each tool
parameter. This method is called after internal validation."""
return
def execute(self, parameters, messages):
"""The source code of the tool."""
arcpy.AddMessage("Input was: " + parameters[0].valueAsText)
arcpy.AddMessage("******************************************")
arcpy.SetParameterAsText(1, "Output is: " + parameters[0].value)
return
It runs fine in ArcMap:
Then I right click the result, and Share As… Geoprocessing Service. I added stuff for parameter description, and tool description and summary. I set the information level to Info. Checked for no warnings or errors, and clicked publish. It says Published Successfully. I can browse to it, and click Submit Job to test it, and it always fails as not a valid tool:
Job Messages:
esriJobMessageTypeInformative: Submitted.
esriJobMessageTypeInformative: Executing...
esriJobMessageTypeError: ERROR 000816: The tool is not valid.
esriJobMessageTypeError: Failed.
I read a tip somewhere about checking the folder on the server for the packaged python toolbox and try running that from the server. So I tried that too and it runs just fine:
PS C:python27> .ArcGISx6410.7python.exe
Python 2.7.16 (v2.7.16:413a49145e, Mar 4 2019, 01:37:19) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import arcgisscripting
>>> import arcpy
>>> import os
>>> os.chdir(r'C:arcgisarcgisserverdirectoriesarcgissystemarcgisinputMyFolderBasicTool.GPServerextractedv101basictest')
>>> arcpy.ImportToolbox(r".BasicTest.pyt", "Tool")
<module 'Tool' (built-in)>
>>> arcpy.Tool.Tool("Hi There")
Input was: Hi There
******************************************
<Result 'Output is: Hi There'>
>>>
So I’ve never done this successfully, what am I missing? What is invalid about the tool?
I wanted to share that the service runs successfully after performing a repair install of the ArcGIS Server. This fixed some ArcPy dependencies that were broken by running PIP to install a python package on the server. The ERROR 000816: The tool is not valid. message from ArcGIS Server really meant that the ESRI ArcPy environment was messed up.
Correct answer by freshop on March 26, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP