I am running some code in a Pro 2.8.1 notebook that has worked for me in the past to publish hosted feature layers to a Portal. I'm currently trying to publish to AGOL, but I don't think the Portal/AGOL destination matters, because I am getting an error just trying to create the service definition file.
First, I get a layer variable lyr from a map in ArcGIS Pro using map.listLayers(). The layer's source is an FGDB point feature class. I have no problem sharing that map layer as a hosted feature layer in ArcGIS Pro. Also, the layer's visibility checkbox is turned on.
Next, I create a sharing draft for the layer, set some properties, and save as an sddraft (service definition draft) file:
sharing_draft = map.getWebLayerSharingDraft("HOSTING_SERVER", "FEATURE",
publish_name, lyr)
sharing_draft.overwriteExistingService = True
sharing_draft.allowExporting = True
# Also set these sharing_draft properties: summary, description, tags,
# credits, portalFolder, and useLimitations
sharing_draft.exportToSDDraft(r'C:\temp\scratch\Schools.sddraft')
That file creates ok and looks like valid XML in my IDE. As far as I can tell, everything worked up to this point. It's the next part that causes an error:
try:
arcpy.server.StageService(r'C:\temp\scratch\Schools.sddraft',
r'C:\temp\scratch\Schools.sd')
except Exception as ex:
print('{}: {}'.format(type(ex).__name__, ex))
traceback.print_exc()
The print statement produces this:
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.
XML document must have a top level element.
Failed to execute (StageService).
And here's the Traceback:
Traceback (most recent call last):
File "[11]", line 51, in <module>
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\server.py", line 1088, in StageService
raise e
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\server.py", line 1085, in StageService
retval = convertArcObjectToPythonObject(gp.StageService_server(*gp_fixargs((in_service_definition_draft, out_service_definition, staging_version), True)))
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\geoprocessing\_base.py", line 512, in <lambda>
return lambda *args: val(*gp_fixargs(args, True))
arcgisscripting.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.
XML document must have a top level element.
Failed to execute (StageService).
I did find BUG-000126867 here, but that doesn't seem applicable, since it's about a geocoding service.
Any ideas on what to do next?