ArcGIS Python API Overwrite Feature Service Not Working

07-24-2023 11:00 AM
New Contributor III

****Edit. When I publish a zipped file geodatabase with only layers and perform the overwrite function, it works as expected, but when I publish a zipped file geodatabase with multiple layers and tables, that is where it is erroring out on me. I believe the ArcGIS Python API and its overwrite function are limited to one or the other kind of dataset, not a combination of both layers and tables.

I am trying to overwrite a feature service on ArcGIS Online using the ArcGIS API for Python. The code I am using is:


# Import necessary libraries
from arcgis.gis import GIS
from arcgis.features import FeatureLayerCollection

# Log in to your AGOL account
gis = GIS("", "Your Username", "Your Password")

# Access the service using its ID
service_item = gis.content.get('d4a4d33b25434986a249666c64daf9dc')

# Access the feature layer collection associated with the service
flc = FeatureLayerCollection.fromitem(service_item)

# Define the path to your file
gdb_zip_path = 'C:\\GIS_Project\\Navajo County ETL Process\\DATAMARK VEP Dataset\\'

# Overwrite the feature service


However, when I try to run this script, I get the following error:

`TypeError: can only concatenate str (not "NoneType") to str`

The traceback points towards this line of code:


From my understanding, this error might be occurring because the item I am trying to overwrite is not inside a specific folder in my content, causing issues when the API tries to concatenate a string with `None`. However, I have confirmed that this item is at the root of my content and not inside a specific folder.

Has anyone encountered this issue before, and if so, how did you resolve it?

5 Replies
Occasional Contributor

The following line of script allows me to overwrite an existing file.
arcpy.env.overwriteOutput = True

New Contributor III

@Shauna-RaeBrown I believe that would work as expected if I was working only with feature classes but communicating with a feature class to a feature service would require using the ArcGIS Python API.

0 Kudos
by Anonymous User
Not applicable

From the docs of overwrite- Only hosted feature layer collection services can be overwritten.

I think you nailed it in your edit; just upload separately.

New Contributor III

@Anonymous User Kind of odd that the manual way through AGOL of dropping a file geodatabase that contains both layers & tables is capable of an overwrite but using the ArcGIS Python API workflow it doesn’t work?

0 Kudos
Esri Esteemed Contributor

@ArizonaGIS this could be another solution to try.

0 Kudos