I'm all new to Python, and 'Im stuck with a problem:

Is it possible to use UpdateCursor on Feature Layers in AGOL?

I am trying something like this:

from arcgis.gis import GIS

gis = GIS("https://arcgis.com", "xxxxxx")

import arcpy

fs=gis.content.search(query="title:xxx, owner:xxxx", max_items=5000,)

kort = fs.layer[0]

fields = ["Fabrikat", "Entreprenør"]

with arcpy.da.UpdateCursor(kort, fields) as cursor:

    for row in cursor:
        if row[0] == "ABB":
               row[1] = "3"

but its popping up with this error:

RuntimeError Traceback (most recent call last) in 2 lag = query_result1 3 fields = ["Fabrikat", "Entreprenør"] ----> 4 with arcpy.da.UpdateCursor(lag, fields) as cursor: 5 for row in cursor: 6 if row[0] == "ABB":

RuntimeError: 'in_table' is not a table or a featureclass

How can I make the cursor "eat" the layer?

  • You've tagged this with 10.2, but you're using Python3.
    – Vince
    Commented Jun 5, 2020 at 1:58

1 Answer 1


The error is saying the UpdateCursor does not like the input, it is NOT a "table or featureclass".

If you do a type on your layers, you'll see its an object specific to the ArcGIS Python API. And you're trying to use an arcpy cursor that wants either a table or feature class.

l = f.layers[0]
>> arcgis.features.layer.FeatureLayer

However, the Cursors appear to accept a URL to a feature service. So you can modify your code slightly and use the URL:

url = kort.url
with arcpy.da.UpdateCursor(url, fields) as cursor:

    for row in cursor:
        if row[0] == "ABB":
               row[1] = "3"

My testing shows you do NOT need to provide authentication with a private Feature Service (as long as you've created your GIS object as the owner of the service). However, you can also try this workflow to pass in a token.

g = GIS("https://www.arcgis.com", USER, PASS)

token = g._con.token

fs = g.content.search(query="title:My Service", max_items=10)
url = fs[0].layers[0].url

featureset = arcpy.FeatureSet()
authenticatedURL = url + "?token={}".format(token)

with arcpy.da.UpdateCursor(authenticatedURL , "*") as cursor:
    for row in cursor:
        row[0] = "hello"
  • That is brilliant ..! But instead another error appears :RuntimeError Traceback (most recent call last) <ipython-input-7-8573a7a88453> in <module> 2 fields = ["Fabrikat", "Entreprenør"] 3 with arcpy.da.UpdateCursor(url, fields) as cursor: ----> 4 for row in cursor: 5 if row[0] == "ABB": 6 row[1] = "3" RuntimeError: ERROR: code:400, , Unable to perform query. Please check your parameters., Bad syntax in request. ....What could that be?
    – Hubertus
    Commented Jun 4, 2020 at 19:13
  • That may come down to how you're running the code. I did all my testing inside ArcGIS Pro's Python Window. It might be how you're authenticated? Or maybe its the fields (Entreprenør) using special characters? You may need to set an encoding? There are so many things it might be, its very hard to say.
    – KHibma
    Commented Jun 5, 2020 at 0:32
  • Thanks for taking your time. When I run it inside ArcgisPro, it works fine, but I would like to run it as a stand-alone script. It seems not to be the encoding, I get the same result on another field without danish letters. But maybe its the wrong way of doing it, there is probably a better method when working with Agol... but the cursor method is more understandable for a non-pogrammer like me...
    – Hubertus
    Commented Jun 5, 2020 at 6:45
  • I added another bit of code that you can follow to authenticate the FS using a token when in the arcpy world. However, I could edit a private service that I owned. So I'm not sure if this is the problem or not. Note, I'm using ArcGIS Pro 2.5. Which version are you using?
    – KHibma
    Commented Jun 5, 2020 at 11:25
  • I just see this now! It works! Thanks. I dont know why I need to pass a token , but its works! You made my day - thanks!
    – Hubertus
    Commented Jun 8, 2020 at 9:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.