Extracting mpk fails while executing as a GP Service

2269
1
03-30-2016 11:25 AM
Jose_FrancisK_J
New Contributor
Hi,

We have a custom tool to extract an mpk file to a specific location.
Below is the python code we used to extract the mpk file:
import arcpy
import os

arcpy.env.overwriteOutput = True
# set folder that contains packages to extract
arcpy.env.workspace = "N:/geoprocessing"
wrksp = arcpy.env.workspace

arcpy.AddMessage("wrksp : " + wrksp )
arcpy.ExtractPackage_management(wrksp + "/J6.mpk", "J6")

While executing this script as a tool in ArcMap, it is executing successfully with the following message:

Running script extract...
wrksp : N:/geoprocessing
Completed script extract...

Once we made this as a GP service and access it via browser,  it fails. Following is the message retrieved:
esriJobMessageTypeInformative: Running script extract...
esriJobMessageTypeInformative: wrksp : D:\arcgisserver\directories\arcgissystem\arcgisinput\test_extract.GPServer\extracted\v101
esriJobMessageTypeInformative: Failed script extract...
esriJobMessageTypeError: Traceback (most recent call last): File "D:\arcgisserver\directories\arcgissystem\arcgisinput\test_extract.GPServer\extracted\v101\my_toolboxes\module1.py", line 31, in arcpy.ExtractPackage_management(wrksp + "/J6.mpk", g_ESRI_variable_1) File "c:\program files\arcgis\server\arcpy\arcpy\management.py", line 7383, in ExtractPackage raise e ExecuteError: Failed to execute. Parameters are not valid. ERROR 000732: Input Package: Dataset D:\arcgisserver\directories\arcgissystem\arcgisinput\test_extract.GPServer\extracted\v101/J6.mpk does not exist or is not supported Failed to execute (ExtractPackage).
esriJobMessageTypeError: Failed to execute (extract).

We could see that the application is not able to detect the workspace while running as GP tool. Also, the workspace we used here is a mapped Network path. I tried even by changing this to C drive. That also fails.

Any help regarding this is appreciable.

0 Kudos
1 Reply
AndrewKeith3
Occasional Contributor

The best thing to do would be to register a folder where the map packages will be located with ArcGIS Server.  But, to answer your question, I think you have path issue.  Try changing this line:

arcpy.ExtractPackage_management(wrksp + "/J6.mpk", "J6")

to this:

import os
arcpy.ExtractPackage_management(wrksp + os.sep + "J6.mpk", "J6")
0 Kudos