So I've created a geoprocessing Python script tool that I've published as a GP service. This script takes lat/lon coordinates, extracts data from a raster from these coordinates, outputs a .csv and creates an Excel chart from a .vbs script. I can run the Python script on our server from the "C:\arcgisserver\directories\arcgissystem\arcgisinput" path and it works. I'm trying to test the GP service (Execute Task (GET)) from a browser on our REST services page. It says it's successful, but it doesn't actually output the chart. It does create the .csv, but it doesn't run the .vbs script. Here is the result message:
{
"results": [],
"messages": [
{
"type": "esriJobMessageTypeInformative",
"description": "Executing (ChartTest): ChartTest 45 -122 Portland"
},
{
"type": "esriJobMessageTypeInformative",
"description": "Start Time: Wed Jan 25 13:51:23 2017"
},
{
"type": "esriJobMessageTypeInformative",
"description": "Executing (ChartTest): ChartTest 45 -122 Portland"
},
{
"type": "esriJobMessageTypeInformative",
"description": "Start Time: Wed Jan 25 13:51:23 2017"
},
{
"type": "esriJobMessageTypeInformative",
"description": "Running script ChartTest..."
},
{
"type": "esriJobMessageTypeInformative",
"description": "Completed script ChartTest..."
},
{
"type": "esriJobMessageTypeInformative",
"description": "Succeeded at Wed Jan 25 13:51:23 2017 (Elapsed Time: 0.70 seconds)"
},
{
"type": "esriJobMessageTypeInformative",
"description": "Succeeded at Wed Jan 25 13:51:23 2017 (Elapsed Time: 0.71 seconds)"
}
]
}
I had a lot of trouble publishing this GP service because the Python script creates a .vbs, and these types of scripts can't be copied to the server. I got around this by changing the ".vbs" reference to ".txt" and publishing. I changed it back to ".vbs" on the server. I'm not sure if the server is blocking the .vbs or what. There are no errors in the server logs.
Solved! Go to Solution.
Just figured it out. It was getting hung up on "plt.show()" in the matplotlib script. It works on the REST page now.
Lloyd, I marked this as Assumed Answered since I did not see a question above. It looks like you have a workaround or were you looking for some more alternatives? IF so, you can unmark the Assumed, and add you question....or change it to a discussion instead of a question.
Rebecca,
Sorry, the question is, why is the last part of my tool not running? The results say it is, but the .vbs script is not being created and the chart is not being generated. This script tool runs to completion in IDLE on the ArcGIS server machine, but not from the REST services page online. The messages say "succeeded" after I run execute task (GET), but it only gets to the step where the .csv is created. It seems like the server is blocking the .vbs from running, but I'm not sure. I've been talking to tech support about this, but I haven't gotten an answer yet. We're thinking it may be a permissions issue, ie the user online doesn't have permission to run a script on our local server machine.
The "Completed script ChartTest" is printed after the .vbs script is run? Are you running Idle as the same user running the ArcGIS Server Windows service? I'd suggest you take a look at the Event Viewer to see if there are any errors there. Also, you can run ProcMon and set a filter for .vbs script to see if it's actually called on. I don't think it's a permission issue, as the .vbs script resides in the arcgisinput folder, which the ArcGIS Server account would have full access to. The online user doesn't need permission to that folder; the user needs permission to the service and the user running the service needs permissions to whatever is being processed within the service so running Idle as the same user that runs the ArcGIS Server Windows service may be a good test. Make sure you're not running Idle as an admin when you run the script, as I doubt the GP service would run with elevated permission.
The .vbs doesn't reside in the arcgis server folder, it's written on the fly by the Python script and run. I have been running the IDLE from an admin account on the ArcGIS server machine.
Ah, I see. Does the .vbs file get created in the scratch directory? How are you constructing the path to the output .vbs file within the script?
When the Python script tool is run it follows these steps:
1. Extract values from raster based on input lat/lon coordinates
2. Write these values to .csv
3. Write .vbs to create chart of values in Excel
4. Run .vbs
Both the .csv and .vbs are written to the C:\temp drive of the server machine. These files will be overwritten everytime the tool is run. When I run the script in IDLE, everything works. When I enter the parameters into the execute task form on the GP service page, it gets to step 2, and writes the .csv to the temp drive. It doesn't get past step 2.
Both the .vbs and .csv are created dynamically in Python modules like so:
vbs_filepath = "C:\\temp\\Build_raster_Charts.vbs"
csv_filepath = "C:\\temp\\ + "chart_data_for_"\
+ location_label + ".csv"
Is that the syntax within the unpublished script, or the published one? What happens if you construct the path using the os.path.join function and the scratch folder environment variable:
vbs_filepath = os.path.join(arcpy.env.scratchFolder,"Build_raster_Charts.vbs")
csv_filepath = os.path.join(arcpy.env.scratchFolder,"{0}.csv".format(local_label)
By doing this, you use the scratch workspace of the Server when running the GP service, (the arcgisjobs directory), to maintain unique job folders for each run of the tool that are cleaned up automatically by the software. Typically, the published script will be updated to use this directory during the publishing process. Also, using os.path.join avoids potential path problems when publishing GP services.
OK. So would I define the scratch folder like so?
arcpy.env.scratchFolder = "C:\arcgisserver\directories\arcgisjobs"
There was not a scratch folder defined when I published the service
The scratch folder is set automatically by the software in both ArcMap and ArcGIS Server. In ArcMap it'd be set to C:\Users\<your_username>\Documents\ArcGIS\scratch by default, and on the Server it'll be set to C:\arcgisserver\directories\arcgisjobs\<service_name>\<unique_jobID>\scratch. It will create this folder whenever the service is run and put any intermediate or output data there. You don't need to overwrite it within your script, just use arcpy.env.scratchFolder to call on it
Ex.
vbs_filepath = os.path.join(arcpy.env.scratchFolder,"Build_raster_Charts.vbs")
arcpy.env.scratchWorkspace is the <unique_jobID> folder and arcpy.env.scratchGDB is the <unique_jobID>\scratch.gdb file geodatabase.
This may not specifically address the problem you're running into, but it's a best practice and can help to make sure that things are written to the jobs directory correctly. What you can also do is add a few more arcpy.AddMessage print statements so you get a better indication of how far along the script has progressed, for example:
arcpy.AddMessage("Creating .vbs file.")
...
arcpy.AddMessage("Created .vbs file.")