999999 "unexpected" error on arcpy.server.StageService

1063
4
01-20-2022 09:04 PM
davedoesgis
Occasional Contributor III

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? 

 

0 Kudos
4 Replies
by Anonymous User
Not applicable

Can you successfully publish the layer from the Pro GUI? Can you compare the xml with another (successfully published) for differences, if any that could cause the XML document must have a top level element error?

0 Kudos
davedoesgis
Occasional Contributor III

Thanks for your response, Jeff. Yes, it publishes to AGOL from the GUI with no problems. 

I should clarify that I mistakenly thought the code up to this point didn't care which portal I was signed into, or if I was signed in at all, but it doesn't run if I'm not signed in. 

I ran the script with Pro signed into our Enterprise Portal and my code published it just fine. Then, I  used the Visual Studio Code file comparison on the sddraft files from Portal (succeeded) and AGOL (error). First, let me say the XML structure of the two files is exactly the same. The only differences I see that are different are exactly the things you would expect to vary. None of the differences are structural to the XML, i.e.: all differences are just the text in between XML open and close tags. Here are the differences: 

  • ID GUIDs in a few places
  • URLs to the Portal vs. AGOL
  • A token (basically a GUID)
  • Username
  • There are a bunch of PropertySetProperty XML tags with different values
    • Key AdminVersion has a value of 9.40 on AGOL and 8.20 on our Portal
    • Key PortalVersion  has a value of 9.4 on AGOL and 8.2 on our Portal
    • Key IsPortal is false on AGOL and true on our Portal
    • Key ServerRunTimeVersion is 203 on AGOL and 208 on our Portal (this seems odd that our version is higher than AGOL!)
  • Create time

I think it's a good idea to compare them, but unfortunately, I don't see a smoking gun here. 

 

0 Kudos
FabioNeiraAlzate
New Contributor II

I have the same error, do you find a solution?

0 Kudos
davedoesgis
Occasional Contributor III

I ended up publishing the layers manually in Pro and lost interest in this problem. My recollection is that I ended up getting the code to work in a brand new APRX much later. I'm not sure if the APRX had gotten corrupted or maybe Esri upgraded AGOL in the interim. I never really felt like I identified the problem, much less the solution, but I do believe I eventually got it to work by starting over in a fresh APRX. 

0 Kudos