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:
Hello,
I am trying to over-write a feature service in ArcGIS online. I am using the ESRI's code and twigged it depending on my need. However, I am getting the following error:
File C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\sharing.py, in exportToSDDraft: Line 24: return _convertArcObjectToPythonObject(self._arc_object.exportToSDDraft(out_sddraft, self)) ValueError: Service and/or folder name contains unsupported characters: : ,. ,/
Any suggestions on this issue will be thankfully appreciated.
I know this is a year late but I was getting the same error when trying to create a gp service from a very similar script. The script would work locally but would crash with this error when trying to run from the gp service. The fix for me would be to add the 'offline' property for sddraft. This would allow my 'arcgis' user to export the sddraft file even if it wasnt signed in. So possibly adding this line would fix your issue:
sddraft = m.getWebLayerSharingDraft(server_type,"MAP_IMAGE",service_name)
sddraft.federatedServerUrl = federated_server_url
sddraft.overwriteExistingService = True
sddraft.offline = True
sddraft.exportToSDDraft(sddraft_output_filename)
Thanks. That sorted out my issue
@RyanJones6 that fixed my issues. Thanks!