When using a derivative of the template map service publishing examples given in many places throughout ESRI documentation, I have the following working (I've stripped this down significantly)...
sharing_draft = m.getWebLayerSharingDraft("FEDERATED_SERVER", "MAP_IMAGE", service)
sharing_draft.federatedServerUrl = <federatedServerUrl>
...
sharing_draft.exportToSDDraft(sddraft_output_filename)
..
arcpy.StageService_server(sddraft_output_filename, sd_output_filename)
...
inSdFile = sd_output_filename
inServer = <serverUrl>
inServiceName = <service name>
...
arcpy.UploadServiceDefinition_server(inSdFile, inServer, inServiceName, ...)
What exactly is the difference - if any - between what I am referring to here as >federatedServerUrl. and <serverUrl>? And what exactly is the format of the URL expected here? I have it working in one environment and am using the exact same string (URL) for both variables. In another environment, the same code fails with ...
ExecuteError: ERROR 999999: Something unexpected caused the tool to fail.
Please refer to the error help for potential solutions, or contact Esri
Technical Support http://esriurl.com/support.
Failed to execute (StageService).
The only difference is that I'm using a different URL but the same one in both places. It's a valid URL that mimics the first environment's URL and includes the webadaptor name. It successfully created the SD Draft file. So the URL seems to work fine for that steps.
Very frustrating. I have used this a bunch of times in both environments and now it fails.