Select to view content in your preferred language

ArcMap needs to be open to make UploadServiceDefinition_server run

690
3
Jump to solution
12-03-2017 10:03 PM
AlexChen
New Contributor III

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")
Tags (1)
0 Kudos
1 Solution

Accepted Solutions
JakeSkinner
Esri Esteemed Contributor

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:

Publishing SDs shapefiles and CSVs | ArcGIS for Developers 

View solution in original post

0 Kudos
3 Replies
JakeSkinner
Esri Esteemed Contributor

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:

Publishing SDs shapefiles and CSVs | ArcGIS for Developers 

0 Kudos
AlexChen
New Contributor III

Thanks Jake! Does the new ArcGIS API for Python work with ArcGIS 10.1 that I have to stick with?

0 Kudos
JakeSkinner
Esri Esteemed Contributor

You only need Python 3.5 for the API.  Here are instructions on how to set it up:

install and set up | ArcGIS for Developers 

0 Kudos