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.
<SPAN class="">
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"
<SPAN>print arcpy.SignInToPortal_server("MYNAME", "PASSWORD", "</SPAN><A class="jive-link-external-small" href="https://community.esri.com/external-link.jspa?url=http%3A%2F%2Fwww.arcgis.com%2F" target="_blank">http://www.arcgis.com/</A><SPAN>")</SPAN>
# 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()
<BR class="" /></SPAN>When I ran the script with ArcMap opened, it worked well. However, if I closed ArcMap and ran it, it threw the following error:
<SPAN class="">
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).</SPAN>
The same error was thrown even if I left out all the optional params like below
<SPAN class="">arcpy</SPAN><SPAN class="">.</SPAN><SPAN class="">UploadServiceDefinition_server</SPAN><SPAN class="">(</SPAN><SPAN class="">sd</SPAN><SPAN class="">,</SPAN><SPAN class=""> </SPAN><SPAN class="">"My Hosted Services"</SPAN><SPAN class="">)</SPAN>