ERROR

ArcGIS Notebooks: ERROR 1: Cannot encode value

First Published: July 24, 2026
Last Published: July 24, 2026

Error Message

In ArcGIS Notebooks, when exporting extracted deleted features from a hosted feature layer to a new feature class, the following error message is returned:

Error: 
ERROR 1: Cannot encode value
The error message displayed in ArcGIS Notebooks cell

In some cases, the following error message is returned:

Error:   
ERROR 1: Cannot encode Y value
Alternative error message displayed in ArcGIS Notebooks cell

Cause

The spatial reference of the FeatureSet is not correctly defined before exporting the deleted features to a new feature class. As a result, the geometry values cannot be encoded during feature class creation.

Solution or Workaround

  1. Open the notebooks in ArcGIS Online.
  2. Copy and paste the code below to export deleted features extracted from a hosted feature layer to a new feature class.
    1. Import the libraries from the Python API and authenticate the connection to ArcGIS Online.
from arcgis.gis import GIS
gis = GIS("Home")                              
print("Logged in as:", gis.users.me.username)  
from datetime import datetime, timedelta, timezone
import pandas as pd
from arcgis.features import FeatureLayerCollection
from arcgis.features import FeatureSet
print("Starting")
Note:
After pasting the code, click Run this cell and advance Run this cell and advance icon to execute the cell before proceeding to the next step. 
    1. Retrieve the target feature layer collection and initialize the UTC time zone for the feature layer. Replace <ITEM_ID> with the feature layer item ID.
item_id = "<ITEM_ID>"
flc_item = gis.content.get(item_id)    
flc = FeatureLayerCollection.fromitem(flc_item)
utc_now = datetime.now(timezone.utc)
start_time_ms = int((utc_now - timedelta(hours=24)).timestamp() * 1000)
print(utc_now)
    1. Extract deleted features from the feature layer. Replace <replicaServerGen_Value> with the replicaServerGen value obtained from the replica JSON file. Refer to ArcGIS REST APIs: Sync workflow examples for more information.
changes = flc.extract_changes(
    layers=[0],
    servergen=<replicaServerGen_Value>,  
    return_inserts=False,
    return_updates=False,
    return_deletes=True
)
    1. Create a FeatureSet from the deleted features and assign the correct spatial reference.
print("Processing deleted features")

deletes = changes["edits"][0]["features"].get("deletes", [])

feature_list = []

for feat in deletes:
    geom = feat.get("geometry")

    # skip only truly invalid geometry
    if geom is None:
        continue

    feature_list.append({
        "attributes": feat.get("attributes"),
        "geometry": geom
    })

if not feature_list:
    raise Exception("No valid features.")

feature_set = FeatureSet.from_dict({"features": feature_list})

# FIX part
feature_set.spatial_reference = {"wkid": 3857}

print(feature_set.sdf)
    1. Export the deleted features to a CSV file and an output feature class.
print("sending to csv")
output_csv_path = "/arcgis/home/output_data.csv"
feature_set.sdf.spatial.to_table(location=output_csv_path)

print("sending to feature class (GDB)")

# File geodatabase feature class
output_path = "/arcgis/home/test.gdb/NewTestClass"
feature_set.sdf.spatial.to_featureclass(location=output_path)

print("Done")
)

The code block below shows the full sample script.

from arcgis.gis import GIS
gis = GIS("Home")                              
print("Logged in as:", gis.users.me.username)  
from datetime import datetime, timedelta, timezone
import pandas as pd
from arcgis.features import FeatureLayerCollection
from arcgis.features import FeatureSet
print("Starting")

item_id = "fbc594fdbff1435780ebc36cf09666e6"
flc_item = gis.content.get(item_id)    
flc = FeatureLayerCollection.fromitem(flc_item)
utc_now = datetime.now(timezone.utc)
start_time_ms = int((utc_now - timedelta(hours=24)).timestamp() * 1000)
print(utc_now)


changes = flc.extract_changes(
    layers=[0],
    servergen=11360400,   # ReplicaServerGen value
    return_inserts=False,
    return_updates=False,
    return_deletes=True
)

print("Processing deleted features")

deletes = changes["edits"][0]["features"].get("deletes", [])

feature_list = []

for feat in deletes:
    geom = feat.get("geometry")

    # skip only truly invalid geometry
    if geom is None:
        continue

    feature_list.append({
        "attributes": feat.get("attributes"),
        "geometry": geom
    })

if not feature_list:
    raise Exception("No valid features.")

feature_set = FeatureSet.from_dict({"features": feature_list})

feature_set.spatial_reference = {"wkid": 3857}

print(feature_set.sdf)

print("sending to csv")
output_csv_path = "/arcgis/home/output_data.csv"
feature_set.sdf.spatial.to_table(location=output_csv_path)

print("sending to feature class (GDB)")

# File geodatabase feature class
output_path = "/arcgis/home/test.gdb/NewTestClass"
feature_set.sdf.spatial.to_featureclass(location=output_path)

print("Done")

The output message is displayed in the cell.

The output message

Article ID: 000042526

Software:
  • ArcGIS Online
  • ArcGIS API for Python

Get support with AI

Resolve your issue quickly with the Esri Support AI Chatbot.

Start chatting now

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Start chatting now

Go to download options