Hello,
I created a Hosted Feature Layer in my portal, when I try to add features to this layer using python I get error 10500 Database error has occurred.
Here's the code:
from arcgis.gis import GIS
from arcgis.features import FeatureLayer
# Log in to GIS
gis = GIS("https://myportal.com", "username", "password")
# URL of the hosted feature layer
feature_layer_url = "https://myportal.com/arcgis/rest/services/my_service/FeatureServer/0"
# Access the hosted feature layer
feature_layer = FeatureLayer(feature_layer_url)
# Example: Data to add
user_data = [
{"userid": "user_001"},
{"userid": "user_002"},
{"userid": "user_003"}
]
# List to store features to be added
features_to_add = []
# Convert the data into the required format for features (attributes)
for user in user_data:
feature = {
"attributes": {
"userid": user["userid"]
}
}
features_to_add.append(feature)
# Add the new features to the hosted feature layer
add_result = feature_layer.edit_features(adds=features_to_add)
# Check the result
if add_result['addResults'][0]['success']:
print("Features added successfully.")
else:
print(f"Error: {add_result['addResults'][0].get('error', 'Unknown error')}")
I'm trying to do it as I'm working with a normal layer and maybe this is the issue ?
The weird thing is that I was able to append data to the layer using a csv (directly from the portal) - but my aim is to use code
I already checked the settings:
Do you have any idea on how I can do it ?
Thanks
Solved! Go to Solution.
Here's what the prints look like
Seems normal to me, I get the right data
what do you see if you print the variable 'feature_layer'?
I'd recommend printing everything out and just try a simple hardcoded input to test.
Here's what the prints look like
Seems normal to me, I get the right data
Apparently I had an issue with my db - issue is solved