Select to view content in your preferred language

Update hosted feature service with a zip file, Unknown Error - error code: 500

130
3
a week ago
LienPham1
New Contributor II

Hi, 

I'm seeking assistance to update my hosted feature layer titled "Stands_nd_statistics" using a zipped shapefile. My objective is to both update existing features with new data and add new features where necessary. I've attempted to achieve this using the append operation in ArcGIS Python API, but I encountered an Unknown Error with error code 500.

import arcpy, os, json,  zipfile
from arcgis.gis import GIS
from arcgis import features
from arcgis.mapping import WebMap
from arcgis.features import FeatureLayerCollection
from arcgis.features import FeatureLayer

gis = GIS("https://www.arcgis.com", "username", "password")

search_result = gis.content.search("title:Stands_nd_statistics", item_type = "Feature Layer")
layer_item = search_result[0]
feature_layer = FeatureLayer(layer_item.url)

# Upload the zipped shapefile as an item to your GIS
zip_path = r"P:\Projects\Stands_nd_statistics.zip"
shapefile_item = gis.content.add({'title': 'Stands_nd_statistics_upload','type': 'Shapefile'}, data=zip_path)

feature_layer.append(item_id=shapefile_item.id, upload_format="shapefile", upsert=False)

Exception: Unknown Error

Any guidance or insights on how to troubleshoot and resolve this issue would be greatly appreciated! Thank you.

Tags (1)
0 Kudos
3 Replies
MichaelSnook
Occasional Contributor III

I'm seeing the same type of error as I posted here :

https://community.esri.com/t5/arcgis-api-for-python-questions/after-3-3-upgrade-featurelayercollecti...

It looks like it could be a file size issue but I don't see anywhere in the updated documentation how to get around it.

0 Kudos
EarlMedina
Esri Regular Contributor

Here's an idea. Load that shapefile into a spatial dataframe.

sdf = pd.DataFrame.spatial.from_featureclass("path\to\your\data\census_example\cities.shp")

 

Then append like this instead:

 

adds = sdf.spatial.to_featureset()
feature_layer.edit_features(adds=adds)

 

0 Kudos
JakeSkinner
Esri Esteemed Contributor

@LienPham1 have you tried executing ArcGIS Pro's Append tool?  This provides an upsert option which will update existing features with new data and add new features.  To use the upsert option, make sure the field your using in the hosted feature service has a unique index:

JakeSkinner_0-1719227929898.png

 

 

0 Kudos