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.
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")
import os arcpy.ExtractPackage_management(wrksp + os.sep + "J6.mpk", "J6")