<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Cannot open URL of hosted feature layer in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/cannot-open-url-of-hosted-feature-layer/m-p/1258618#M8570</link>
    <description>&lt;P&gt;Hi internet peoples!&amp;nbsp; I'm hoping that someone could help me in testing an error that I've run into related to accessing a hosted feature layer via an update cursor.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to update one field based upon the value in another field, in a hosted feature layer.&amp;nbsp; I used a Notebook in ArcGIS Pro (v2.9.5) to test a script that would accomplish what I need to do.&amp;nbsp; I connect to my GIS(), access the item, obtain the URL of the layer (as there is only one), and pass it to a search cursor to perform the calculations needed for each row.&amp;nbsp; This worked beautifully in a Notebook in Pro.&lt;/P&gt;&lt;P&gt;I want to set up the script to run nightly via a Task, so I copied my script to a Notebook in ArcGIS Online.&amp;nbsp; I'm using the ArcGIS Notebook Python 3 Advanced - 7.0 Runtime.&amp;nbsp; All parts of the script work, except when trying to access the URL in the search cursor.&amp;nbsp; I can access the item, access the layer, and access the URL, but when I pass the URL to the search cursor, I get the error:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Input In [7], in &amp;lt;cell line: 1&amp;gt;()
----&amp;gt; 1 with arcpy.da.UpdateCursor(roads_url, fields) as cursor:
      2     for row in cursor:
      3         newDate = row[0]

RuntimeError: cannot open 'https://services1.arcgis.com/###########/arcgis/rest/services/HFL_NAME/FeatureServer/0'&lt;/LI-CODE&gt;&lt;P&gt;I tried adding a token to the URL to get an authenticated URL, but I received the same error. I also tried the Advanced 6.0 Runtime and received the same error.&amp;nbsp; &amp;nbsp; Further, I tried to create a FeatureSet and load the data into it via the URL, but received a similar error:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Input In [77], in &amp;lt;cell line: 1&amp;gt;()
----&amp;gt; 1 roads_fset = arcpy.FeatureSet(roads_url)
      2 roads_fset

File /opt/conda/lib/python3.9/site-packages/arcpy/arcobjects/mixins.py:1049, in FeatureSetMixin.__init__(self, *args, **kwargs)
   1047 _BaseArcObject.__init__(self)
   1048 if args or kwargs:
-&amp;gt; 1049     self._arc_object.load(*gp_fixargs(args), **gp_fixkwargs(kwargs))

RuntimeError: RecordSetObject: Cannot open table for Load&lt;/LI-CODE&gt;&lt;P&gt;I have found no help documentation or forum questions related to this very specific issue.&amp;nbsp; My code is below, if someone wants to try to recreate this error in an ArcGIS Online Notebook.&amp;nbsp; Just switch out the UpdateCursor for a SearchCursor, while using your own hosted feature layer.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;#search for the feature layer 
portal_item = gis.content.get('abcdefghijklmnop')

#access the item's feature layers
roads_layer = portal_item.layers[0]

#return the url of the feature layer
roads_url = roads_layer.url

#field names for UpdateCursor calculations
fields = ['FieldOne','FieldTwo']

#UpdateCursor accessing the feature layer via its URL
with arcpy.da.UpdateCursor(roads_url, fields) as cursor:
    for row in cursor:
        #Do Something
del row, cursor&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance to anyone who can test this script and/or determine if this is really a BUG!&lt;/P&gt;</description>
    <pubDate>Wed, 15 Feb 2023 19:02:16 GMT</pubDate>
    <dc:creator>Mark_Prettyman</dc:creator>
    <dc:date>2023-02-15T19:02:16Z</dc:date>
    <item>
      <title>Cannot open URL of hosted feature layer</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/cannot-open-url-of-hosted-feature-layer/m-p/1258618#M8570</link>
      <description>&lt;P&gt;Hi internet peoples!&amp;nbsp; I'm hoping that someone could help me in testing an error that I've run into related to accessing a hosted feature layer via an update cursor.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to update one field based upon the value in another field, in a hosted feature layer.&amp;nbsp; I used a Notebook in ArcGIS Pro (v2.9.5) to test a script that would accomplish what I need to do.&amp;nbsp; I connect to my GIS(), access the item, obtain the URL of the layer (as there is only one), and pass it to a search cursor to perform the calculations needed for each row.&amp;nbsp; This worked beautifully in a Notebook in Pro.&lt;/P&gt;&lt;P&gt;I want to set up the script to run nightly via a Task, so I copied my script to a Notebook in ArcGIS Online.&amp;nbsp; I'm using the ArcGIS Notebook Python 3 Advanced - 7.0 Runtime.&amp;nbsp; All parts of the script work, except when trying to access the URL in the search cursor.&amp;nbsp; I can access the item, access the layer, and access the URL, but when I pass the URL to the search cursor, I get the error:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Input In [7], in &amp;lt;cell line: 1&amp;gt;()
----&amp;gt; 1 with arcpy.da.UpdateCursor(roads_url, fields) as cursor:
      2     for row in cursor:
      3         newDate = row[0]

RuntimeError: cannot open 'https://services1.arcgis.com/###########/arcgis/rest/services/HFL_NAME/FeatureServer/0'&lt;/LI-CODE&gt;&lt;P&gt;I tried adding a token to the URL to get an authenticated URL, but I received the same error. I also tried the Advanced 6.0 Runtime and received the same error.&amp;nbsp; &amp;nbsp; Further, I tried to create a FeatureSet and load the data into it via the URL, but received a similar error:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
Input In [77], in &amp;lt;cell line: 1&amp;gt;()
----&amp;gt; 1 roads_fset = arcpy.FeatureSet(roads_url)
      2 roads_fset

File /opt/conda/lib/python3.9/site-packages/arcpy/arcobjects/mixins.py:1049, in FeatureSetMixin.__init__(self, *args, **kwargs)
   1047 _BaseArcObject.__init__(self)
   1048 if args or kwargs:
-&amp;gt; 1049     self._arc_object.load(*gp_fixargs(args), **gp_fixkwargs(kwargs))

RuntimeError: RecordSetObject: Cannot open table for Load&lt;/LI-CODE&gt;&lt;P&gt;I have found no help documentation or forum questions related to this very specific issue.&amp;nbsp; My code is below, if someone wants to try to recreate this error in an ArcGIS Online Notebook.&amp;nbsp; Just switch out the UpdateCursor for a SearchCursor, while using your own hosted feature layer.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;#search for the feature layer 
portal_item = gis.content.get('abcdefghijklmnop')

#access the item's feature layers
roads_layer = portal_item.layers[0]

#return the url of the feature layer
roads_url = roads_layer.url

#field names for UpdateCursor calculations
fields = ['FieldOne','FieldTwo']

#UpdateCursor accessing the feature layer via its URL
with arcpy.da.UpdateCursor(roads_url, fields) as cursor:
    for row in cursor:
        #Do Something
del row, cursor&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance to anyone who can test this script and/or determine if this is really a BUG!&lt;/P&gt;</description>
      <pubDate>Wed, 15 Feb 2023 19:02:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/cannot-open-url-of-hosted-feature-layer/m-p/1258618#M8570</guid>
      <dc:creator>Mark_Prettyman</dc:creator>
      <dc:date>2023-02-15T19:02:16Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot open URL of hosted feature layer</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/cannot-open-url-of-hosted-feature-layer/m-p/1258629#M8571</link>
      <description>&lt;P&gt;Not sure what's wrong but I wouldn't use cursors for this for performance reasons.&lt;/P&gt;&lt;P&gt;In my experience ArcPy cursors are total dogs for working with hosted feature layers compared to using the &lt;A href="https://developers.arcgis.com/python/api-reference/arcgis.features.toc.html#featurelayer" target="_self"&gt;FeatureLayer&lt;/A&gt; type in the ArcGIS API for Python.&amp;nbsp; Use query() the features you want - only grabbing the field you need for calculation and the OIDs - then create a bunch of updates with just the OIDs and the derived field and push them through using edit_features().&lt;/P&gt;&lt;P&gt;Your mileage may vary but I've found this approach&amp;nbsp;&lt;EM&gt;much&lt;/EM&gt; better.&lt;/P&gt;&lt;P&gt;Also, secondary benefit, the query/edit_features approach doesn't require an advanced runtime.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Feb 2023 19:26:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/cannot-open-url-of-hosted-feature-layer/m-p/1258629#M8571</guid>
      <dc:creator>MobiusSnake</dc:creator>
      <dc:date>2023-02-15T19:26:50Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot open URL of hosted feature layer</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/cannot-open-url-of-hosted-feature-layer/m-p/1258634#M8572</link>
      <description>&lt;P&gt;Personal opinion: if you're working with hosted layers, you're better of using the ArcGIS Python API entirely instead of including ArcPy.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;#search for the feature layer 
portal_item = gis.content.get('abcdefghijklmnop')

#access the item's feature layers
roads_layer = portal_item.layers[0]

#field names for calculations
fields = ['objectid','FieldOne','FieldTwo']

# return a dataframe w/ features
df = roads_layer.query(out_fields=fields, as_df=True)

# calculate the field value in your dataframe
df['FieldTwo'] = # some calculation

# apply edited dataframe back to service as edits
roads_layer.edit_features(edits=df.spatial.to_featureset())&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 15 Feb 2023 19:30:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/cannot-open-url-of-hosted-feature-layer/m-p/1258634#M8572</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2023-02-15T19:30:26Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot open URL of hosted feature layer</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/cannot-open-url-of-hosted-feature-layer/m-p/1259521#M8573</link>
      <description>&lt;P&gt;Thank you both for the helpful suggestions as alternatives to accomplish the update of the field!&amp;nbsp; I appreciate that they don't require the Advanced runtime, too.&amp;nbsp; I accepted both of your replies as the solution as I took a bit from each suggestion for my working script.&amp;nbsp; Thanks again!&lt;/P&gt;</description>
      <pubDate>Fri, 17 Feb 2023 20:07:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/cannot-open-url-of-hosted-feature-layer/m-p/1259521#M8573</guid>
      <dc:creator>Mark_Prettyman</dc:creator>
      <dc:date>2023-02-17T20:07:44Z</dc:date>
    </item>
  </channel>
</rss>

