Hello All,
I have been running the original script provided by Jake Skinner and it has been working. But, with upgrades to desktop and ArcGIS Pro, I have run into some snags and I'm revisiting this script for automated updates to two of my feature services. Below is the script that I am running and the error that I am receiving. I have tried completely deleting the old feature service and service definition file from AGOL and starting over and I still get the error. If anybody would be so kind to assist, I would greatly appreciate it!
HERE IS THE SCRIPT:
import arcpy
import os, sys
from arcgis.gis import GIS
### Start setting variables
# Set the path to the project
prjPath = r"C:\Spam\PY\FeatureServiceUpdate\TaxParcel\TaxParcelsUpdate.aprx"
# Update the following variables to match:
# Feature service/SD name in arcgis.com, user/password of the owner account
sd_fs_name = "Tax_Parcels"
portal = "https://acpa.maps.arcgis.com" # Can also reference a local portal
user = "ACPA"
password = "***************"
# Set sharing options
shrOrg = True
shrEveryone = True
shrGroups = ""
### End setting variables
# Local paths to create temporary content
relPath = os.path.dirname(prjPath)
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, allow_exporting=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))
THIS IS HOW FAR I GET WITH THE SCRIPT AND THE ERROR I RECEIVE:
Python 3.6.9 |Anaconda, Inc.| (default, Jul 30 2019, 14:00:49) [MSC v.1915 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>>
RESTART: C:\Spam\PY\FeatureServiceUpdate\TaxParcel\TaxParcelFeatureServiceUpdate.py
Creating SD file
Connecting to https://acpa.maps.arcgis.com
Search for original SD on portal…
Found SD: Public_Parcels, ID: cea64d901d7c4282879e600d9f34113d n Uploading and overwriting…
Overwriting existing feature service…
User cant overwrite this service, using this data, as this data is already referring to another service.
Traceback (most recent call last):
File "C:\Spam\PY\FeatureServiceUpdate\TaxParcel\TaxParcelFeatureServiceUpdate.py", line 45, in <module>
fs = sdItem.publish(overwrite=True)
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\__init__.py", line 8818, in publish
folder, buildInitialCache)
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\_impl\portalpy.py", line 372, in publish_item
resp = self.con.post(path, postdata, files)
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\_impl\connection.py", line 1183, in post
self._handle_json_error(resp_json['error'], errorcode)
File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\_impl\connection.py", line 1204, in _handle_json_error
raise RuntimeError(errormessage)
RuntimeError: User cant overwrite this service, using this data, as this data is already referring to another service.
(Error Code: 500)
>>>