Select to view content in your preferred language

How to published mxd to overwrite existing service on ArcGIS server using PYTHON?

05-28-2014 11:41 PM
New Contributor II
Hi All,

I would like to automate publishing  mxd using Python to my ArcGIS server

I did this successfully manually using the menu: Share as -> Service, Overwrite Existing service etc...

Using Python, I successfully completed following steps:

But I could not find a way to arcpy.UploadServiceDefinition_server() to publish my mxd.

print "service definition draft created"
    arcpy.AddMessage("service definition draft created")

    # Set local variables
    inSdFile = sd
    con = "GIS Servers\\arcgis on HPWS32_6080 (admin)"
    inServer = con
    inServiceName = 'districtwise'
    inCluster = "default"
    inFolderType = "EXISTING"
    inFolder = "weather"
    inStartup = "STARTED"
    inOverride = "OVERRIDE_DEFINITION"
    inMyContents = "NO_SHARE_ONLINE"
    inPublic = "PRIVATE"
    inOrganization = "NO_SHARE_ORGANIZATION"
    inGroups = ""

    print "publishing local variables defined"
    arcpy.AddMessage("publishing local variables defined")

    # stage and upload the service if the sddraft analysis did not contain errors
    if analysis['errors'] == {}:
        # Execute StageService
        arcpy.StageService_server(sddraft, sd)
        print "StageService_server created"
        arcpy.AddMessage("StageService_server created")
        # Execute UploadServiceDefinition
        arcpy.UploadServiceDefinition_server(inSdFile, inServer, inServiceName, 
                                     inCluster, inFolderType, inFolder, 
                                     inStartup, inOverride, inMyContents, 
                                     inPublic, inOrganization, inGroups)
        print "Uploaded..."

        # if the sddraft analysis contained errors, display them
        print analysis['errors']

I am getting following errors:

An error occured on line 63
Failed to execute. Parameters are not valid.
ERROR 000732: Server: Dataset GIS Servers\arcgis on HPWS32_6080 (admin) does not exist or is not supported
WARNING 001404: You are not signed in to ArcGIS Online.
Failed to execute (UploadServiceDefinition).

I am able to upload service using Model builder with same parameters but not with python... Somewhere I got this link

(This is unfortunately a bug at 10.2, and has been logged, #NIM093766: When uploading to My Hosted Services, arcpy.UploadServiceDefinition fails with error "000732 Server: Dataset My Hosted Services does not exist or is not supported".].)

which I am  sharing with u all..  I must be missing something. Any help would be really appreciated.

Thanks in advance!
0 Kudos
7 Replies
Regular Contributor


Did you end up finding a solution to this problem?

Have you got it working now?



0 Kudos
Occasional Contributor II

Same problem here

I've found the exact same question mentioned here -

Overwrite existing map service in ArcGIS Server 10.1 (through ArcPy) - Geographic Information System...

and yet I can't seem to manage overwriting an existing service!

Tried everything already!!

DIVYA SAHU‌ your error suggests that there is an error with the params.

try changing the string - con = "GIS Servers\\arcgis on HPWS32_6080 (admin)"

into - "GIS Servers/arcgis on HPWS32_6080 (admin)"

just make sure this is the right name as shown in the arcgis catalog under the "GIS Servers" section

Occasional Contributor

I stumbled onto this thread as I am also attempting to overwrite an existing service on ArcGIS Server with python. The script provided by stackexchange still doesn't work for me. I'm getting the following errors:

Traceback (most recent call last):

  File "C:\scripts\", line 35, in <module>

    con, True, None, summary, tags)

  File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\", line 18

1, in fn_

    return fn(*args, **kw)

  File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\", line

382, in CreateMapSDDraft

    return convertArcObjectToPythonObject(arcgisscripting._createMapSDDraft(*gp_

fixargs([map_document, out_sddraft, service_name, server_type, connection_file_p

ath, copy_data_to_server, folder_name, summary, tags], True, False)))

IOError: Missing raster band wavelength properties.

Any ideas?Python

0 Kudos
MVP Notable Contributor

No time to decipher your code, but here is an example that is working in 10.2.1. (this also disables KML)  This will republish from mxd the services in docList.  This also disables schema locking, so If you want your services to lock your schema, will have to remove that part.

import arcpy
import xml.dom.minidom as DOM
from arcpy import env
import os
env.workspace = r'\\myserver\iMapMXDs\PublicWorks\drafts'
arcpy.env.overwriteOutput = True
docList = ['PW_Irrigation','PW_Water','PW_Storm','PW_Sewer','PW_SewerTracking']

for service in docList:
    # Reference map document.
    mapDoc = arcpy.mapping.MapDocument(r'\\myserver\iMapMXDs\PublicWorks' + os.sep + service + '.mxd')
    sddraft = r'\\myserver\iMapMXDs\PublicWorks\drafts' + os.sep + service + '.sddraft'
    Server = r"GIS Servers\arcgis on myserver (admin)"
    arcpy.AddMessage(("RePublishing - " + service + " From " + mapDoc.filePath))
    inServiceDefinitionDraft = sddraft
    inSdFile = outServiceDefinition = service + ".sd"
    newType = 'esriServiceDefinitionType_Replacement'
    # Create sddraft.
    arcpy.mapping.CreateMapSDDraft(mapDoc, sddraft, service, 'ARCGIS_SERVER')
    # The Server Object Extension (SOE) to disable.
    soe = 'KmlServer'
    # Read the sddraft xml.
    doc = DOM.parse(sddraft)
    # Find all elements named TypeName. This is where the server object extension (SOE) names are defined.
    typeNames = doc.getElementsByTagName('TypeName')
    for typeName in typeNames:
        # Get the TypeName we want to disable.
        if == soe:
            extension = typeName.parentNode
            for extElement in extension.childNodes:
                # Disabled SOE.
                if extElement.tagName == 'Enabled':
           = 'false'
    descriptions = doc.getElementsByTagName('Type')
    for desc in descriptions:
        if desc.parentNode.tagName == 'SVCManifest':
            if desc.hasChildNodes():
       = newType
    keys = doc.getElementsByTagName('Key')
    for key in keys:
      if key.hasChildNodes():
        if == 'schemaLockingEnabled':
   = 'false'
        if == 'textAntialiasingMode':
   = 'None'
    f = open(sddraft, 'w')
    doc.writexml( f )
    # Execute StageService
    arcpy.StageService_server(sddraft, outServiceDefinition)
    # Execute UploadServiceDefinition
    arcpy.UploadServiceDefinition_server(inSdFile, Server,"#","#","EXISTING","PublicWorks","STARTED")
0 Kudos
Occasional Contributor II


I actually solved this problem already by using some premade python tools that enables start/stop/deleting existing services.

So my script starts to search for the name of the relevant service name

using - getServiceList()

if he exists then I delete him

using - stopStartServices()

and after all that I publish my new service

using - arcpy.UploadServiceDefinition_server()

its not perfect but it works perfectly

0 Kudos
MVP Notable Contributor

I tried this method at first and works fine to just re-publish.  However, it didn't seem to pick up changes to things like adding a value to a Domain.  For this, I had to re-create the service definition from the mxd first, then re-publish and the new values show.

I also right-click on the service in ArcCatalog and modify the settings some (turn off KML and schema locking).  This method is the only way I could find to accomplish this.


0 Kudos
Occasional Contributor II

Yeah sorry I actually forgot to mention that part.. you need to create the SD file and my script takes him from a network path and run the publish method

0 Kudos