ListDataFrames failed after publishing as a service

3120
2
05-12-2016 11:10 AM
YingCao
New Contributor


I've got a pretty simple script which runs successfully on my local (ArcGIS Desktop), but after i publish it as a service, it throws error when it is being called. The path of the mxd should be globally accessible and the data frame should also be valid in mxd file. So what could the reason of not running as a service? Thanks!!

import arcpy

mapDoc = arcpy.mapping.MapDocument(r"\\server_name\folder_name\test.mxd")                       

dataFrames = arcpy.mapping.ListDataFrames(mapDoc)

dataFrame = dataFrames[0]

dataFrameSR = dataFrame.spatialReference

The error message is

esriJobMessageTypeError: Traceback (most recent call last): File "\\server_name\folder_name\testscript.py", line 175, in dataFrames = arcpy.mapping.ListDataFrames(mapDoc) File "d:\program files\arcgis\server\arcpy\arcpy\utils.py", line 181, in fn_ return fn(*args, **kw) File "d:\program files\arcgis\server\arcpy\arcpy\mapping.py", line 1479, in ListDataFrames result = mixins.MapDocumentMixin(map_document).listDataFrames(wildcard) File "d:\program files\arcgis\server\arcpy\arcpy\arcobjects\mixins.py", line 728, in listDataFrames return list(reversed(list(self.dataFrames))) File "d:\program files\arcgis\server\arcpy\arcpy\arcobjects\mixins.py", line 695, in dataFrames return map(convertArcObjectToPythonObject, self.pageLayout.dataFrames) AttributeError: 'NoneType' object has no attribute 'dataFrames'

0 Kudos
2 Replies
DanPatterson_Retired
MVP Emeritus

on a lark rename your project using a capital T instead of a small t to check to see if \t is being misinterpreted

this has reared its head recently on another thread and the common link is escape characters

see NIM082676 - Unexpected behavior occurs when using input parame..

from Create Geodatabase Connection mishandles escape characters

0 Kudos
RebeccaStrauch__GISP
MVP Emeritus

I posted this, and a snippet of code https://community.esri.com/message/627561#comment-627561

but thought I would share it here to, in case the mxd version is an issue for you too.

I was getting this error "AttributeError: 'NoneType' object has no attribute 'dataFrames'" today in a script that I was running against all STARTED services in AGS (10.2.2).  I'm looping thru all those services, finding the MXDs and searching to see if the FGDB I'm needing to update is in the MXD, then creating a list of the services I need to STOP so I could replace the FGDB and then restart.  This error was showing up on only one of my services (and therefore crashing).  It turns out the for some reason, that mxd must be saved as 10.3.x, or so the error seems to indicate if I try to open with ArcMap 10.2.2. 

The error occurred  with "lyrList = arcpy.mapping.ListLayers(mxd)"  so I wrapped in in a ListDataFrames loop, with no luck.  Since there is no easy or reliable way to check for the version of an .mxd (from several hours of searching and testing a half dozen suggestions), I found the try: my best option, and I'll just include this service in my STOP list, just in case.

The strange thing is I can stop and start this service in 10.2.2 without any known issue, at least manually.  Stopping/starting them programatically is next, so we'll see if it causes issues, but so far it seems the ListLayers or more likely the ListDataFrames is the culprit.  A bug maybe??  Anyway, the versions or what version of ArcMap you can open the mxd in might be something to check out.

0 Kudos