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
try:
os.remove(sd)
except OSError:
pass
# if required, sign in to My Hosted Services
print "SignInToPortal_server"
print arcpy.SignInToPortal_server("MYNAME", "PASSWORD", "http://www.arcgis.com/")
# 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
arcpy.SignOutFromPortal_server()
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 "PubToAGOL_Test.py", line 38, in <module>
"PUBLIC", "SHARE_ORGANIZATION", "")
File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\server.py", 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
ted
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")
Solved! Go to Solution.
Hi Alex,
This is a known issue, that I believe broke at 10.2. When uploading the SD to ArcGIS Online, it will piggy back off of ArcGIS Desktop's connection.
As a workaround you leverage the new ArcGIS API for Python to publish the SD file:
Hi Alex,
This is a known issue, that I believe broke at 10.2. When uploading the SD to ArcGIS Online, it will piggy back off of ArcGIS Desktop's connection.
As a workaround you leverage the new ArcGIS API for Python to publish the SD file:
Thanks Jake! Does the new ArcGIS API for Python work with ArcGIS 10.1 that I have to stick with?
You only need Python 3.5 for the API. Here are instructions on how to set it up: