Hey all, I am trying to create a tool that will allow me to enter my portal username and password, then overwrite an existing map service once it has been updated in ArcGIS Pro.
import arcpy
import os
UserName = arcpy.GetParameterAsText(0)
Password = arcpy.GetParameterAsText(1)
arcpy.SignInToPortal("https://giswebmap.isrb.com/portal",UserName,Password)
outdir = r"I:\GIS\GIS_Monthly_Updates\ForDeveloping\PCC_ServeDef"
service_name = "PCC"
sddraft_filename = service_name + ".sddraft"
sddraft_output_filename = os.path.join(outdir,sddraft_filename)
sd_filename = service_name + ".sd"
sddraft_output_filename = os.path.join(outdir,sd_filename)
aprx = arcpy.mp.ArcGISProject(r"I:\GIS\GIS_Monthly_Updates\ForDeveloping\GIS_Monthly_Update.aprx")
m = aprx.listMaps('PCC')[0]
server_type = "FEDERATED_SERVER"
federated_server_url = "https://giswebmap.isrb.com/server"
sddraft = m.getWebLayerSharingDraft(server_type,"MAP_IMAGE",service_name)
sddraft.federatedServerUrl = federated_server_url
sddraft.overwriteExistingService = True
sddraft.exportToSDDraft(sddraft_output_filename)
print("Start Staging")
arcpy.StageService_server(sddraft_output_filename, sddraft_output_filename)
print("Start Uploading")
arcpy.UploadServiceDefinition_server(sddraft_output_filename, federated_server_url)
print("Finish Publishing")
This is a sample code that I copied and pasted, then manipulated, from ESRI's website, hoping that it would work. However when I run it I keep getting this error message:
Traceback (most recent call last):
File "I:\GIS\GIS_Monthly_Updates\DevelopmentScripts\PublishServiceDefinition.py", line 25, in <module>
sddraft.exportToSDDraft(sddraft_output_filename)
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\sharing.py", line 68, in exportToSDDraft
return _convertArcObjectToPythonObject(self._arc_object.exportToSDDraft(out_sddraft,self))
ValueError: Unable to create the manifest (sddraft file). An unspecified error occurred.
Any suggestions to what may be causing this and how I can go about fixing it? Thanks in advance for the help.