Arcgis server 10.1 and openpyxl error 816

10-04-2012 01:17 PM
New Contributor III
I'm trying to create a GP-service that uses the python openpyxl 3. party module.
When i'm running it from arcmap(Standard), it works like a charm, publich the result as gp-service on the server.
When i then sets up the flexviewer 3.0 using the gp-widget - i get an error 000816 tool is not valid, and nothing else.

import osimport arcpy
import uuid
import openpyxl

class Toolbox(object):
    def __init__(self):
        """Define the toolbox (the name of the toolbox is the name of the
        .pyt file)."""
        self.label = "Toolbox"
        self.alias = ""

        # List of tool classes associated with this toolbox = [Tool]

class Tool(object):
    def __init__(self):
        """Define the tool (tool name is the name of the class)."""
        self.label = "Tool"
        self.description = ""
        self.canRunInBackground = False

    def getParameterInfo(self):
        """Define parameter definitions"""

        param0 = arcpy.Parameter(
    param0.value = 'OpenPyXl'
    params = [param0]
        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."""

    def updateMessages(self, parameters):
        """Modify the messages created by internal validation for each tool
        parameter.  This method is called after internal validation."""

    def execute(self, parameters, messages):
        """The source code of the tool."""
    wb = openpyxl.Workbook(optimized_write=True)
        ws = wb.create_sheet() 
    wb_file = r'C:\arcgisserver\directories\arcgisoutput\_ags_' + str(uuid.uuid4()) + '_' + parameters[0].value + '.xlsx'
##    arcpy.AddMessage(wb_file)

this is the python toolbox i'm trying to publish, it's quite simple, the only thing it does is making a xlsx file in the  c:\arcgisserver\directories\arcgisoutput folder with the name _ags_UUID_OpenPyXl.xlsx

The output folder is set up in the Datastore on the server.
I've tried to copy the openpyxl folder from the python folder to the same folder as the python toolbox, no luck at that.
I've tried to add a sys.path.append and the path to the openpyxl folder, no luck at that.

somebody please help me, my larger tool wont work before i've solved this problem.
0 Kudos
3 Replies
Esri Regular Contributor
Change the wb_file parameter to use the arcpy.env.scratchFolder instead of hard coding the directory.  GP tools when fired off from server create a temp directory for each job, and you want to do your work there.  Then you would use arcpy.SetParameterAsText or arcpy.SetParameter() to return the results back to the end user.

# change
wb_file = r'C:\arcgisserver\directories\arcgisoutput\_ags_' + str(uuid.uuid4()) + '_' + parameters[0].value + '.xlsx'
# to
wb_file = env.scratchFolder + os.sep + "myfilename.xlsx"

Hope this helps.
0 Kudos
New Contributor III
Hi Andrew,
That didn't work, I've come as far as to think it has something to do with the 3. party module, openpysl.
I don't think it gets imported when the tool runs from the server.

0 Kudos
Esri Regular Contributor
You need to have the 3rd party module installed on your server, and you need to ensure it's the 64-bit version. 

ArcGIS Server using python 2.7 64-bit where as the desktop version uses the 32-bit version.

See: for some help with this issue.
0 Kudos