UPDATE
I had to delete the WebUpdate.sd and WebUpdate.sddraft files. The script wasn't able to overwrite those 2 files for some reason. If anyone has ideas to why that might be the case that would be great to know.
Hi,
I changed the relPath = r"C:\GIVE_A_FILE_DIRECTORY" to a local folder and still getting this error.
Creating SD file
Traceback (most recent call last):
File "C:/ScheduledScripts/TRC/updatewebmap1.py", line 33, in <module>
arcpy.mp.CreateWebLayerSDDraft(mp, sddraft, sd_fs_name, 'MY_HOSTED_SERVICES', 'FEATURE_ACCESS','', True, True)
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\mp.py", line 105, in CreateWebLayerSDDraft
return _convertArcObjectToPythonObject(arcgisscripting._mapping.CreateWebLayerSDDraft(*_gp_fixargs([map_or_layers, out_sddraft, service_name, server_type, service_type, folder_name, overwrite_existing_service, copy_data_to_server, enable_editing, allow_exporting, enable_sync, summary, tags, description, credits, use_limitations], True)))
RuntimeError
>>>
The script was working for over a year until last month. Only change is updating ArcPro to 2.7.1. I successfully overwrote the layer manually through ArcPro.
Any insight would be great.
import arcpy
import os, sys
from arcgis.gis import GIS
### Start setting variables
# Set the path to the project
prjPath = r"Path of aprx"
# Update the following variables to match:
# Feature service/SD name in arcgis.com, user/password of the owner account
sd_fs_name = "NAME OF LAYER"
portal = "NAME OF PORTAL" # Can also reference a local portal
user = "NAME OF USER"
password = "PASSWORD"
# Set sharing options
shrOrg = False
shrEveryone = False
shrGroups = "Group"
### End setting variables
# Local paths to create temporary content
relPath = r"C:\ScheduledScripts\TRC"
sddraft = os.path.join(relPath, "WebUpdate.sddraft")
sd = os.path.join(relPath, "WebUpdate.sd")
# Create a new SDDraft and stage to SD
print("Creating SD file")
arcpy.env.overwriteOutput = True
prj = arcpy.mp.ArcGISProject(prjPath)
mp = prj.listMaps()[0]
arcpy.mp.CreateWebLayerSDDraft(mp, sddraft, sd_fs_name, 'MY_HOSTED_SERVICES', 'FEATURE_ACCESS','', True, True)
arcpy.StageService_server(sddraft, sd)
print("Connecting to {}".format(portal))
gis = GIS(portal, user, password)
# Find the SD, update it, publish /w overwrite and set sharing and metadata
print("Search for original SD on portal…")
sdItem = gis.content.search("{} AND owner:{}".format(sd_fs_name, user), item_type="Service Definition")[0]
print("Found SD: {}, ID: {} n Uploading and overwriting…".format(sdItem.title, sdItem.id))
sdItem.update(data=sd)
print("Overwriting existing feature service…")
fs = sdItem.publish(overwrite=True)
if shrOrg or shrEveryone or shrGroups:print("Setting sharing options…")
fs.share(org=shrOrg, everyone=shrEveryone, groups=shrGroups)
print("Finished updating: {} – ID: {}".format(fs.title, fs.id))