Hi all,
I am trying to automate the publishing of map services, and am having issues with the function arcpy.StageService_server. The code works when executed within the python window in ArcGIS Pro 3.x but fails in propy, proenv and visual studio code while using the library in arcgispro-py3.

This is for a ArcGIS Server 10.9.1 which is unfederated.
I have also tested this on another 10.9.1 federated enterprise, as well as 11.1 using getWebLayerSharingDraft function and am able to reproduce the error.
sd = mp.getWebLayerSharingDraft('FEDERATED_SERVER', 'MAP_IMAGE', servicename)
sd.federatedServerUrl = self.server_url
For Standalone, I am using:
sd = arcpy.sharing.CreateSharingDraft('STANDALONE_SERVER', 'MAP_SERVICE', 'test', mp)
sd.targetServer = '\\\\Server1234\\automate\\agsconnection\\agsconnection.ags'
I have tried exporting the python script from pro and executing it returns the same result as well.

Sample code I am trying to run:
import arcpy
arcpy.server.StageService(r"C:\Work\Projects\Web Service Automation\sddrafts\test.sddraft", r"C:\Work\Projects\Web Service Automation\sds\test.sd", None)
I have also tested using double slashes ("C:\\Work\\..."), back slashes, as well as a shared network path (r"\\server\automate\..." and "\\\\server\\automate\\..) with full control.
I have added a breakpoint and it's throwing an error on the function convertArcObjectToPythonObject in server.py line at 1167:

IIS, Server, Portal, DS have all been registered with a CA-Signed SSL Certificate.
I have also tried adding the following line:
ssl._create_default_https_context = ssl._create_unverified_context
For some more context, I have no issues executing the GIS module on a federated server in VSC. I am able to sign in, create/delete items, etc.
Does anyone know why ArcGIS Pro handles this differently from VSCode?
Cheers,
Derrick