I have a geoprocessing service that was successfully published to our Server instance. I’m using 10.3 which means we could not publish unless it was successfully run as a tool in ArcMap. But now when I try calling the GP service form my client I am getting an error that the dataframe object was not created properly. I am not sure why the script works in ArcMap and not on the server. Here is the script
import sys, string, arcpy, os
# get default script location
scriptPath = sys.path[0]
# Construct paths to mxd
mxdFilePath = os.path.join(scriptPath,"Mymxd.mxd")
mxd = arcpy.mapping.MapDocument(mxdFilePath)
df = arcpy.mapping.ListDataFrames(mxd)[0]
shpPath = arcpy.GetParameterAsText(0)
newLayer = arcpy.mapping.Layer(shpPath)
arcpy.mapping.AddLayer(df,newLayer,"TOP")
arcpy.RefreshActiveView()
del newLayer
del mxd
And here is the error
esriJobMessageTypeInformative: Submitted.
esriJobMessageTypeInformative: Executing...
esriJobMessageTypeInformative: Executing (MyService): MyService "Feature Set" C:Users~AppDataLocalTempMyServiceMyService_122215_1630_gpserverj25ae6595a46840369acebfbd9d3fd12fscratchPrintout1.pdf
esriJobMessageTypeInformative: Start Time: Tue Dec 22 16:55:18 2015
esriJobMessageTypeInformative: Executing (MyService): MyService "Feature Set" C:Users~AppDataLocalTempMyServiceMyService_122215_1630_gpserverj25ae6595a46840369acebfbd9d3fd12fscratchPrintout1.pdf
esriJobMessageTypeInformative: Start Time: Tue Dec 22 16:55:18 2015
esriJobMessageTypeInformative: Running script MyService...
esriJobMessageTypeInformative: Success reading the mxd from \myservermysharearcgisserverdirectoriesarcgissystemarcgisinputMyServiceMyService_122215_1630.GPServerextractedv101folderMyService.mxd
esriJobMessageTypeError: Traceback (most recent call last): File "\myservermysharearcgisserverdirectoriesarcgissystemarcgisinputMyServiceMyService_122215_1630.GPServerextractedv101folderGeoprocessingService_Test.py", line 20, in df = arcpy.mapping.ListDataFrames(mxd)[0] File "e:arcgisserverarcpyarcpyutils.py", line 181, in fn_ return fn(*args, **kw) File "e:arcgisserverarcpyarcpymapping.py", line 1479, in ListDataFrames result = mixins.MapDocumentMixin(map_document).listDataFrames(wildcard) File "e:arcgisserverarcpyarcpyarcobjectsmixins.py", line 728, in listDataFrames return list(reversed(list(self.dataFrames))) File "e:arcgisserverarcpyarcpyarcobjectsmixins.py", line 695, in dataFrames return map(convertArcObjectToPythonObject, self.pageLayout.dataFrames) AttributeError: 'NoneType' object has no attribute 'dataFrames'
esriJobMessageTypeError: Failed to execute (MyService).
esriJobMessageTypeInformative: Failed at Tue Dec 22 16:55:19 2015 (Elapsed Time: 1.00 seconds)
esriJobMessageTypeError: Failed to execute (MyService).
esriJobMessageTypeInformative: Failed at Tue Dec 22 16:55:19 2015 (Elapsed Time: 1.00 seconds)
esriJobMessageTypeError: Failed.