<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic 999999 &amp;quot;unexpected&amp;quot; error on arcpy.server.StageService in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/999999-quot-unexpected-quot-error-on-arcpy-server/m-p/1135739#M63552</link>
    <description>&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;First, I get a layer variable &lt;FONT face="courier new,courier" color="#993300"&gt;lyr&lt;/FONT&gt; from a map in ArcGIS Pro using &lt;FONT face="courier new,courier" color="#993300"&gt;map.listLayers()&lt;/FONT&gt;. 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.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Next, I create a sharing draft for the layer, set some properties, and save as an sddraft (service definition draft) file:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;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')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;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()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The print statement produces this:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;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).&lt;/PRE&gt;&lt;P&gt;And here's the Traceback:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Traceback (most recent call last):
  File "[11]", line 51, in &amp;lt;module&amp;gt;
  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 &amp;lt;lambda&amp;gt;
    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).&lt;/PRE&gt;&lt;P&gt;I did find&amp;nbsp;&lt;SPAN&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/2.8/get-started/release-notes.htm" target="_blank" rel="noopener"&gt;BUG-000126867 here&lt;/A&gt;, but that doesn't seem applicable, since it's about a geocoding service.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Any ideas on what to do next?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 21 Jan 2022 05:06:03 GMT</pubDate>
    <dc:creator>davedoesgis</dc:creator>
    <dc:date>2022-01-21T05:06:03Z</dc:date>
    <item>
      <title>999999 "unexpected" error on arcpy.server.StageService</title>
      <link>https://community.esri.com/t5/python-questions/999999-quot-unexpected-quot-error-on-arcpy-server/m-p/1135739#M63552</link>
      <description>&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;First, I get a layer variable &lt;FONT face="courier new,courier" color="#993300"&gt;lyr&lt;/FONT&gt; from a map in ArcGIS Pro using &lt;FONT face="courier new,courier" color="#993300"&gt;map.listLayers()&lt;/FONT&gt;. 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.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Next, I create a sharing draft for the layer, set some properties, and save as an sddraft (service definition draft) file:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;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')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;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()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The print statement produces this:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;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).&lt;/PRE&gt;&lt;P&gt;And here's the Traceback:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Traceback (most recent call last):
  File "[11]", line 51, in &amp;lt;module&amp;gt;
  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 &amp;lt;lambda&amp;gt;
    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).&lt;/PRE&gt;&lt;P&gt;I did find&amp;nbsp;&lt;SPAN&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/2.8/get-started/release-notes.htm" target="_blank" rel="noopener"&gt;BUG-000126867 here&lt;/A&gt;, but that doesn't seem applicable, since it's about a geocoding service.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Any ideas on what to do next?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jan 2022 05:06:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/999999-quot-unexpected-quot-error-on-arcpy-server/m-p/1135739#M63552</guid>
      <dc:creator>davedoesgis</dc:creator>
      <dc:date>2022-01-21T05:06:03Z</dc:date>
    </item>
    <item>
      <title>Re: 999999 "unexpected" error on arcpy.server.StageService</title>
      <link>https://community.esri.com/t5/python-questions/999999-quot-unexpected-quot-error-on-arcpy-server/m-p/1135799#M63554</link>
      <description>&lt;P&gt;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?&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jan 2022 13:57:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/999999-quot-unexpected-quot-error-on-arcpy-server/m-p/1135799#M63554</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-01-21T13:57:09Z</dc:date>
    </item>
    <item>
      <title>Re: 999999 "unexpected" error on arcpy.server.StageService</title>
      <link>https://community.esri.com/t5/python-questions/999999-quot-unexpected-quot-error-on-arcpy-server/m-p/1135902#M63556</link>
      <description>&lt;P&gt;Thanks for your response, Jeff. Yes, it publishes to AGOL from the GUI with no problems.&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I ran the script with Pro signed into our Enterprise Portal and my code published it just fine. Then, I&amp;nbsp; used the Visual Studio Code file comparison on the sddraft files from Portal (succeeded) and AGOL (error). First, let me say &lt;EM&gt;&lt;U&gt;the XML structure of the two files is exactly the same&lt;/U&gt;&lt;/EM&gt;.&amp;nbsp;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.&amp;nbsp;Here are the differences:&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;ID GUIDs in a few places&lt;/LI&gt;&lt;LI&gt;URLs to the Portal vs. AGOL&lt;/LI&gt;&lt;LI&gt;A token (basically a GUID)&lt;/LI&gt;&lt;LI&gt;Username&lt;/LI&gt;&lt;LI&gt;There are a bunch of PropertySetProperty XML tags with different values&lt;UL&gt;&lt;LI&gt;Key AdminVersion has a value of 9.40 on AGOL and 8.20 on our Portal&lt;/LI&gt;&lt;LI&gt;Key&amp;nbsp;PortalVersion&amp;nbsp; has a value of 9.4 on AGOL and 8.2 on our Portal&lt;/LI&gt;&lt;LI&gt;Key&amp;nbsp;IsPortal is false&amp;nbsp;on AGOL and true on our Portal&lt;/LI&gt;&lt;LI&gt;Key&amp;nbsp;ServerRunTimeVersion is 203 on AGOL and 208 on our Portal (this seems odd that our version is higher than AGOL!)&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;Create time&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;I think it's a good idea to compare them, but unfortunately, I don't see a smoking gun here.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 Jan 2022 17:39:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/999999-quot-unexpected-quot-error-on-arcpy-server/m-p/1135902#M63556</guid>
      <dc:creator>davedoesgis</dc:creator>
      <dc:date>2022-01-21T17:39:57Z</dc:date>
    </item>
    <item>
      <title>Re: 999999 "unexpected" error on arcpy.server.StageService</title>
      <link>https://community.esri.com/t5/python-questions/999999-quot-unexpected-quot-error-on-arcpy-server/m-p/1268720#M67130</link>
      <description>&lt;P&gt;I have the same error, do you find a solution?&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2023 19:41:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/999999-quot-unexpected-quot-error-on-arcpy-server/m-p/1268720#M67130</guid>
      <dc:creator>FabioNeiraAlzate</dc:creator>
      <dc:date>2023-03-16T19:41:02Z</dc:date>
    </item>
    <item>
      <title>Re: 999999 "unexpected" error on arcpy.server.StageService</title>
      <link>https://community.esri.com/t5/python-questions/999999-quot-unexpected-quot-error-on-arcpy-server/m-p/1270990#M67195</link>
      <description>&lt;P&gt;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.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Mar 2023 17:22:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/999999-quot-unexpected-quot-error-on-arcpy-server/m-p/1270990#M67195</guid>
      <dc:creator>davedoesgis</dc:creator>
      <dc:date>2023-03-23T17:22:30Z</dc:date>
    </item>
  </channel>
</rss>

