Select to view content in your preferred language

Error 498 when updating feature layer

171
2
Jump to solution
09-05-2024 12:39 PM
AnthonyCastelletto
Emerging Contributor

Hello Python Community,

    I'm attempting to update a feature layer in Arc GIS Online using Arc GIS Pro's Python Notebooks. I'm fairly competent with Python, but quite new to working with the Python API for Arc GIS Onine. I've been able to connect, find my layer, retrieve features, and edit them. The final step is updating the layer and that's where I've hit a snag. When I execute the update, I get an Invalid Token error (error 498). Can anyone point me towards a solution or show me what I've done wrong?

The code looks something like this:

boocGIS = GIS(host="https://arcgis.com/", client_id="my_client_id")

boocContent = boocGIS.content.advanced_search(query="id: my_feature_id", max_items=max_items)

boocCase = boocGeography.layers[0].query()

#To test my ability to update, I feed the search a specific record id
#Since we describe our records as cases, the attribute is caseID and 1087
#refers to a specific case.
boocCase_feature = [f for f in boocCase if f.attributes['caseID']=='1087'][0]

#Now set some keywords in our case to help users find what they're looking for
boocEdit = boocCase_feature
boocEdit.attributes['keywords'] = 'Marine heatwave prediction forecast aquaculture fishing recreation model, test'

#Now update. This is where I run into the problem
update_result = boocGeography.edit_features(updates=[boocEdit])
update_result

The code above will in end in the invalid token error.

BOOC stands for Benefits of Ocean Observing Catalog and this will be a GIS enabled catalog of applications of the Integrated Ocean Observing System.  Thanks in advance for all your help.

 

 

0 Kudos
1 Solution

Accepted Solutions
JakeSkinner
Esri Esteemed Contributor

Hi @AnthonyCastelletto, below is code I use to perform updates:

from arcgis.gis import GIS

# Variables
client_id = 'pVmEFq81pBTL'
itemId = '3df4deee1a9940519fab3e2c5c5c85f2'

# Connect to AGOL
gis = GIS(host="https://arcgis.com", client_id=client_id)

# Reference layer
lyr = gis.content.get(itemId)

layers = lyr.layers
fset = layers[0].query()
flayer = layers[0]
features = fset.features

# Query feature and update
boocCase_feature = [f for f in features if f.attributes['caseID']=='1087'][0]
boocCase_feature.attributes['keywords'] = 'Marine heatwave prediction forecast aquaculture fishing recreation model, test'
update_result = flayer.edit_features(updates=[boocCase_feature])
print(update_result)

View solution in original post

2 Replies
JakeSkinner
Esri Esteemed Contributor

Hi @AnthonyCastelletto, below is code I use to perform updates:

from arcgis.gis import GIS

# Variables
client_id = 'pVmEFq81pBTL'
itemId = '3df4deee1a9940519fab3e2c5c5c85f2'

# Connect to AGOL
gis = GIS(host="https://arcgis.com", client_id=client_id)

# Reference layer
lyr = gis.content.get(itemId)

layers = lyr.layers
fset = layers[0].query()
flayer = layers[0]
features = fset.features

# Query feature and update
boocCase_feature = [f for f in features if f.attributes['caseID']=='1087'][0]
boocCase_feature.attributes['keywords'] = 'Marine heatwave prediction forecast aquaculture fishing recreation model, test'
update_result = flayer.edit_features(updates=[boocCase_feature])
print(update_result)
AnthonyCastelletto
Emerging Contributor

Hey, Jake. That works well. Thanks for helping me out.

0 Kudos