AnsweredAssumed Answered

ArcMap needs to be open to make UploadServiceDefinition_server run

Question asked by alextaochen on Dec 3, 2017
Latest reply on Dec 4, 2017 by jskinner-esristaff

I have the following Python snippet to run to publish a MXD to ArcGIS Online My Content. I am with ArcGIS 10.1. The sddraft and sd files were both correctly generated.

import sys, os
import shutil
import arcpy, arcgisscripting

sddraft = 'DIR'
sd = 'DIR'

# delete the sd file if it already exists; otherwise pass
except OSError:

# if required, sign in to My Hosted Services
print "SignInToPortal_server"
print arcpy.SignInToPortal_server("MYNAME", "PASSWORD", "")

# create service definition
print "StageService_server"
print arcpy.StageService_server(sddraft, sd)

# publish to My Hosted Services, replacement already allowed as it has been defined in the sddraft file!
print "UploadServiceDefinition_server"
arcpy.UploadServiceDefinition_server(sd, "My Hosted Services", service,
                                     "", "FROM_SERVICE_DEFINITION", "EXISTING",
                                     "STARTED", "OVERRIDE_DEFINITION", "SHARE_ONLINE",
                                     "PUBLIC", "SHARE_ORGANIZATION", "")

# Sign out from ArcGIS Online

When I ran the script with ArcMap opened, it worked well. However, if I closed ArcMap and ran it, it threw the following error:

Traceback (most recent call last):
  File "", line 38, in <module>
  File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\", line 1
255, in UploadServiceDefinition
    raise e
arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000732: Server: Dataset My Hosted Services does not exist or is not suppor
Failed to execute (UploadServiceDefinition).


The same error was thrown even if I left out all the optional params like below

arcpy.UploadServiceDefinition_server(sd, "My Hosted Services")