Map Service properties (arcpy): Error parsing recycleInterval, recycleStartTime, keepAliveInterval

06-08-2016 04:22 AM
New Contributor III

Need to publish web service using arcpy tuning up its properties through the parameter names passing them into function parameter_toggle (see code bellow). We are getting error (see picture bellow) in the parse of XML (output of sddraft analysis) with xml.dom.minidom for the parameters:

- "recycleInterval"

- "recycleStartTime"

- "keepAliveInterval"

These parameters represent service properties:

Specify Recycling Settings:

     - Recycle this configuration every

     - Starting at

Specify Health Check Settings:

     - Check and repair instances every

def mapService(wrkspc, con, service):
   return (sddraft, analysis) # (out_sddraft, out_analysis)

def capability_toggle(doc, server_type, status):
  type_names = doc.getElementsByTagName('TypeName')
   for type_name in type_names:
   if == "{}".format(server_type) and status.lower() == 'on':
  type_name.parentNode.getElementsByTagName("Enabled")[0] = "true"

def parameter_toggle(doc,'maxRecordCount', 'MaxInstances', 'recycleInterval', 'recycleStartTime', 'keepAliveInterval'):
  keys = doc.getElementsByTagName('Key')
   for key in keys:
   if == "{}".format(maxRecordCount) : = 100000
   if == "{}".format(MaxInstances) : = 5
   if == "{}".format(recycleInterval) : = 20
   if == "{}".format(recycleStartTime) : = '04:00'
   if == "{}".format(keepAliveInterval) : = 86400 #seconds

def publishService(out_analysis, out_ssdraft, sd, con):

def main():
   # workspace
  wrkspc = "path_to_workspace"

   # server connection (publisher)
  con = os.path.join(wrkspc, "file.ags")
  service = "service_name"

   # outputs mapservice  
   (out_sddraft, out_analysis) = mapService(wrkspc, con, service)

   # parse of XML (from sddraft analysis)
  doc = dom.parse(out_sddraft)

   with open(out_sddraft, 'w+') as xml:
  capability_toggle(doc, 'WMSServer', 'on')

  parameter_toggle(doc,'maxRecordCount', 'MaxInstances', 'recycleInterval', 'recycleStartTime', 'keepAliveInterval')

  sd = os.path.join(wrkspc,service + '.sd')

  publishService(out_analysis, out_sddraft, sd, con)

if __name__ == '__main__':


0 Kudos
8 Replies
MVP Esteemed Contributor

I don't have time to dig into the why, but the error message is telling you that key.nextSibling.firstChild is None.  Trying to access the 'data' attribute of the first child fails because the NoneType object doesn't have an attribute with that name.  Before calling, maybe do a check to see if there is a first child of the next sibling.

0 Kudos
Esri Frequent Contributor

If you'd rather work with JSON than XML, you could publish the service as is, and then use the Admin API to update the service properties.

0 Kudos
New Contributor III

Jonathan Quinn

Joshua Bixby

How can we access to all the data (map service properties) in xml format/structure?

Thank you,

0 Kudos
MVP Esteemed Contributor

You are running into issues while parsing out_sddraft, so the issue can either be with the contents of out_sddraft or your code to parse it.  Since your code for the mapService() function is incomplete, and you haven't attached an XML file representing out_sddraft, it is hard for people to provide feedback on out_sddraft.

If the content of out_sddraft is what it is supposed to be, then the issue becomes how you are parsing the content.  I hesitate to dive into the code for the parameter_toggle() function because the code you posted cannot be the code you are using because the code you posted will generate a SyntaxError since you have strings as parameter names.

If you expand and update your code, or attach an XML file, I can take another look.

0 Kudos
New Contributor II

We also had problems using ESRI's example code from CreateMapSDDraft—Help | ArcGIS for Desktop  to update draft service definitions. We used an XML beautifier to inspect the ssd_draft to make sure that all nodes that are referenced actually exist. I can't remember exactly but one or two minor changes were required to make it work.

0 Kudos
New Contributor III

Exactly Jon Lynch our current challenge is how to list all nodes and their childs. Ww appreciate if you can give more details on how you solved that

0 Kudos
Occasional Contributor


As Jon Lynch says, Use a common text editor like Notepad++ and then add an XML plugin like XML tools and prettify the XML and you will see the keys and values. Tried to paste the xml examples, the editor messes it up.

As Jonathan Quinn says, I am tending towards editing the json than XML, it seems less clutter to deal with. But I can see why you want to do this - have a map service published as you want right from the start.

New Contributor

After searching a long time the answer found:

change your line:

if == "{}".format(recycleStartTime) : = '04:00'  


if == "{}".format(recycleStartTime) :  
   if  key.nextSibling.firstChild == None:
      x = doc.createTextNode("04:00")