divyasahu20@gmail.com

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

Discussion created by divyasahu20@gmail.com on May 28, 2014
Latest reply on Mar 1, 2016 by sviva.gov.il
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:
arcpy.mapping.CreateMapSDDraft()
arcpy.mapping.AnalyzeForSD()
arcpy.StageService_server()


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..."
        arcpy.AddMessage("Uploaded..")

    else: 
        # 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!

Attachments

Outcomes