I am trying to use arcpy cursors on a hosted feature layer containing a geodatabase with multiple tables and feature classes. After digging around the internet, a few posts seem to allude that I can do this:
https://gis.stackexchange.com/questions/363932/how-can-i-use-updatecursor-in-agol-layers
Whereby, it seems the process is to:
So, code looks something like this:
from arcgis.gis import GIS
import arcpy
gis = GIS("https://www.arcgis.com", "username", "password")
hfl = gis.content.get('itemitd')
url = hfl.tables[8]
with arcpy.da.SearchCursor(url, '*') as cursor:
for row in cursor:
print(row)
Which returns the following error:
RuntimeError: cannot open 'https://services6.arcgis.com/yadda/arcgis/rest/services/nameofhostedfeaturelayer/FeatureServer/10'
I tried using a slightly different approach to grab the item, but is pretty much the same as the above:
hfl = gis.content.search(query="title:nameofhostedfeaturelayer, owner:username", max_items=1000)
url = hfl[0].tables[8].url
with arcpy.da.UpdateCursor(url , "*") as cursor:
for row in cursor:
row[0] = "hello"
cursor.updateRow(row)
Which yields the same error.
Couple notes:
for v in hfl.values():
print(o)
for i in hfl.items():
print(c)
Any suggestions why I am receiving that error?
What I do is load the HFS in once to a FeatureSet then I can use it many times without more calls. I know not your question but it may help you.
specrichF = arcpy.FeatureSet()
specrichF.load(specrichURL)
with arcpy.da.SearchCursor(specrichF,......
Hope that helps
Thanks @DougBrowning I tested your suggestion (think that was a similar approach in one of the other links I posted above) and it returns the following error:
RuntimeError: RecordSetObject: Cannot open table for Load
So, there's something that is preventing the cursor from opening/accessing the table...
I knew I should posted that if it is a table you need to use RecordSet
soilpitF = arcpy.RecordSet()
Thanks again @DougBrowning I think the coding you are providing is correct and you are right. I am trying this on a table but I also tested on a layer as well and it just doesn't seem to be accessing either of them with the cursor.
I did come across an ESRI support document that speaks to the errors I am receiving and how a map service can't access the attribute table, but according to the metadata on my hosted feature service, it is a feature layer, not a map service:
I should have posted a sample URL too. Does it end in FeatureServer? Then you give it the number of the layer you want. You may be giving it the /MapServer URL instead.
url = "https://services1.arcgis.com/Hp6G80Pky0om7QvQ/ArcGIS/rest/services/MyServiceName/FeatureServer/0"
soilpitF = arcpy.RecordSet()
soilpitF.load(url)
Sorry I should have posted the complete code. Seems like you are trying to look it up instead? I would just give it the URL to the service.
You get this from the Item page of the service
Hope that works.