ExecuteError('ERROR 999999: Something unexpected caused the tool to fail. (etc etc)
Failed to execute (UploadServiceDefinition)
I am trying to publish a simple polygon feature layer to ArcGIS Enterprise 10.9.
The SD is created on the server but then the call throws the error before the service is created, so I end up with an SD in Portal but no feature service.
I'll give you a snippet here...
from config import Config
import arcpy
arcpy.SignInToPortal(Config.PORTAL_URL, Config.PORTAL_USER, Config.PORTAL_PASSWORD)
project = arcpy.mp.ArcGISProject("K:/webmaps/basemap/basemap.aprx")
maps = project.listMaps()
mapnames = [map.name for map in maps]
map = maps[mapnames.index('Surveys')]
layer = map.listLayers()[0]
sd_name = "C:/TEMP/Surveys.sd"
sddraft_name = sd_name + "draft"
server_type = "HOSTING_SERVER"
service_name = 'Surveys'
sddraft = map.getWebLayerSharingDraft(server_type, "FEATURE", service_name, [layer])
sddraft.overwriteExistingService = True
sddraft.portalFolder = "Public Works"
sddraft.copyDataToServer = True
sddraft.exportToSDDraft(sddraft_name)
arcpy.env.overwriteOutput = True
arcpy.StageService_server(sddraft_name, sd_name)
arcpy.server.UploadServiceDefinition(sd_name, server_type)
This code executes in jupyter and gives this output
---------------------------------------------------------------------------
ExecuteError Traceback (most recent call last)
<ipython-input-15-7cf61cb19f9b> in <module>
1 arcpy.env.overwriteOutput = True
2 arcpy.StageService_server(sddraft_name, sd_name)
----> 3 result = arcpy.server.UploadServiceDefinition(sd_name, server_type)
C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\server.py in UploadServiceDefinition(in_sd_file, in_server, in_service_name, in_cluster, in_folder_type, in_folder, in_startupType, in_override, in_my_contents, in_public, in_organization, in_groups)
1293 return retval
1294 except Exception as e:
-> 1295 raise e
1296
1297
C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\server.py in UploadServiceDefinition(in_sd_file, in_server, in_service_name, in_cluster, in_folder_type, in_folder, in_startupType, in_override, in_my_contents, in_public, in_organization, in_groups)
1290 from arcpy.arcobjects.arcobjectconversion import convertArcObjectToPythonObject
1291 try:
-> 1292 retval = convertArcObjectToPythonObject(gp.UploadServiceDefinition_server(*gp_fixargs((in_sd_file, in_server, in_service_name, in_cluster, in_folder_type, in_folder, in_startupType, in_override, in_my_contents, in_public, in_organization, in_groups), True)))
1293 return retval
1294 except Exception as e:
C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py in <lambda>(*args)
510 val = getattr(self._gp, attr)
511 if callable(val):
--> 512 return lambda *args: val(*gp_fixargs(args, True))
513 else:
514 return convertArcObjectToPythonObject(val)
ExecuteError: ERROR 999999: Something unexpected caused the tool to fail. Contact Esri Technical Support (http://esriurl.com/support) to Report a Bug, and refer to the error help for potential solutions or workarounds.
Failed to execute (UploadServiceDefinition).
Solved! Go to Solution.
To publish a MAP_IMAGE I have to change the server type to FEDERATED_SERVER, the service type to from FEATURE to MAP_IMAGE and add
I tried using the "Publish" button on the SD page in Portal. That creates a broken feature service and an alery pops up with the "helpful" message "There was an error". I'm not kidding, that's 100% of the error message.
I deleted that layer then tried using this code instead of UploadServiceDefinition
from arcgis.gis import GIS
gis = GIS(Config.PORTAL_URL, Config.PORTAL_USER, Config.PORTAL_PASSWORD)
sd = gis.content.add({}, sd_name)
sd.publish()
This code will quickly transfer the SD file in the add() call and works the same way the Publish button does -- creates a broken service. In this case the returned error message is "Exception: Job failed".
I am now assuming something in the set up of my .sddraft file is at fault. I tried stripping out the extra sddraft options (summary, tags, credits etc) but that had no impact.
To publish a MAP_IMAGE I have to change the server type to FEDERATED_SERVER, the service type to from FEATURE to MAP_IMAGE and add