<?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 Re: script unable to locate AGO layer by title in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/script-unable-to-locate-ago-layer-by-title/m-p/1673014#M11816</link>
    <description>&lt;P&gt;Hi Glen,&lt;/P&gt;&lt;P&gt;Thanks for the response.&amp;nbsp; i now get this error:&lt;/P&gt;&lt;P&gt;# coding: utf-8&lt;/P&gt;&lt;P&gt;# coding: utf-8&lt;/P&gt;&lt;P&gt;from arcgis.gis import GIS&lt;/P&gt;&lt;P&gt;import os&lt;/P&gt;&lt;P&gt;import datetime&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;# --- Configuration ---&lt;/P&gt;&lt;P&gt;AGOL_ORG_URL = "&lt;A href="https://Org-name.maps.arcgis.com" target="_blank"&gt;https://Org-name.maps.arcgis.com&lt;/A&gt;"&lt;/P&gt;&lt;P&gt;USERNAME = "Username"&lt;/P&gt;&lt;P&gt;PASSWORD = "Password"&amp;nbsp;&lt;/P&gt;&lt;P&gt;BACKUP_DIR = r"directory" # Local directory for backups&lt;/P&gt;&lt;P&gt;LAYER_TITLE = "LayerTitle" # Title of the layer to backup&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;# Ensure backup directory exists&lt;/P&gt;&lt;P&gt;if not os.path.exists(BACKUP_DIR):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; os.makedirs(BACKUP_DIR)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;# Authenticate to ArcGIS Online&lt;/P&gt;&lt;P&gt;gis = GIS(AGOL_ORG_URL, USERNAME, PASSWORD)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;# Search for the hosted feature layer&lt;/P&gt;&lt;P&gt;# Note: You may need to refine the search query if the title isn't unique&lt;/P&gt;&lt;P&gt;search_result = gis.content.get("6b945b44045f4012853adbda211e81f8")&lt;/P&gt;&lt;P&gt;if not search_result:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print(f"Layer '{LAYER_TITLE}' not found.")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; exit()&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;item = search_result[0]&lt;/P&gt;&lt;P&gt;print(f"Found item: {item.title}")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;# Export data to a File Geodatabase (FGDB) format&lt;/P&gt;&lt;P&gt;# This creates a new item in AGOL content, which will be deleted later&lt;/P&gt;&lt;P&gt;export_title = f"{item.title}_Backup_{datetime.datetime.now().strftime('%Y%m%d_%H%M%S')}"&lt;/P&gt;&lt;P&gt;export_item = item.export(export_title, "File Geodatabase", wait=True)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;# Download the exported file&lt;/P&gt;&lt;P&gt;download_path = export_item.download(BACKUP_DIR)&lt;/P&gt;&lt;P&gt;print(f"Downloaded backup to: {download_path}")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;# Delete the temporary export item from AGOL content&lt;/P&gt;&lt;P&gt;export_item.delete()&lt;/P&gt;&lt;P&gt;print("Temporary export item deleted from ArcGIS Online.")&lt;/P&gt;&lt;P&gt;print("Backup process complete.")&lt;/P&gt;&lt;P&gt;Traceback (most recent call last):&lt;/P&gt;&lt;P&gt;&amp;nbsp; File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\gis\__init__.py", line 14050, in __getitem__&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return dict.__getitem__(self, k)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ^^^^^^^^^^^^^^^^^^^^^^^^^&lt;/P&gt;&lt;P&gt;KeyError: 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;During handling of the above exception, another exception occurred:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Traceback (most recent call last):&lt;/P&gt;&lt;P&gt;&amp;nbsp; File "&amp;lt;string&amp;gt;", line 28, in &amp;lt;module&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\gis\__init__.py", line 14052, in __getitem__&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if not self._hydrated and not k.startswith("_"):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ^^^^^^^^^^^^&lt;/P&gt;&lt;P&gt;AttributeError: 'int' object has no attribute 'startswith'&lt;/P&gt;</description>
    <pubDate>Mon, 15 Dec 2025 14:57:42 GMT</pubDate>
    <dc:creator>KyleConboy</dc:creator>
    <dc:date>2025-12-15T14:57:42Z</dc:date>
    <item>
      <title>script unable to locate AGO layer by title</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/script-unable-to-locate-ago-layer-by-title/m-p/1671371#M11809</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I don't really do any Python scripting but I found this script to backup a hosted feature layer on AGO to my computer.&amp;nbsp; I'm using the python window in ArcPro 3.53 and I'm getting&amp;nbsp;Layer 'King George BMPs' not found.&amp;nbsp; When I run the script I have the right info for org URL, username, password, and backup directory in place.&amp;nbsp; Anyone have any ideas on why it can't find the layer title?&lt;/P&gt;&lt;P&gt;# coding: utf-8&lt;BR /&gt;from arcgis.gis import GIS&lt;BR /&gt;import os&lt;BR /&gt;import datetime&lt;/P&gt;&lt;P&gt;# --- Configuration ---&lt;BR /&gt;AGOL_ORG_URL = "&lt;A href="https://place-name.maps.arcgis.com" target="_blank"&gt;https://place-name.maps.arcgis.com&lt;/A&gt;"&lt;BR /&gt;USERNAME = "username"&lt;BR /&gt;PASSWORD = "password" # Storing credentials in a script is less secure; consider alternative authentication methods for production environments&lt;BR /&gt;BACKUP_DIR = r"BMPBackup" # Local directory for backups&lt;BR /&gt;LAYER_TITLE = "King George BMPs" # Title of the layer to backup&lt;/P&gt;&lt;P&gt;# Ensure backup directory exists&lt;BR /&gt;if not os.path.exists(BACKUP_DIR):&lt;BR /&gt;os.makedirs(BACKUP_DIR)&lt;/P&gt;&lt;P&gt;# Authenticate to ArcGIS Online&lt;BR /&gt;gis = GIS(AGOL_ORG_URL, USERNAME, PASSWORD)&lt;/P&gt;&lt;P&gt;# Search for the hosted feature layer&lt;BR /&gt;# Note: You may need to refine the search query if the title isn't unique&lt;BR /&gt;search_result = gis.content.search(query=f"title:{LAYER_TITLE} AND type:Feature Layer", max_items=1)&lt;BR /&gt;if not search_result:&lt;BR /&gt;print(f"Layer '{LAYER_TITLE}' not found.")&lt;BR /&gt;exit()&lt;/P&gt;&lt;P&gt;item = search_result[0]&lt;BR /&gt;print(f"Found item: {item.title}")&lt;/P&gt;&lt;P&gt;# Export data to a File Geodatabase (FGDB) format&lt;BR /&gt;# This creates a new item in AGOL content, which will be deleted later&lt;BR /&gt;export_title = f"{item.title}_Backup_{datetime.datetime.now().strftime('%Y%m%d_%H%M%S')}"&lt;BR /&gt;export_item = item.export(export_title, "File Geodatabase", wait=True)&lt;/P&gt;&lt;P&gt;# Download the exported file&lt;BR /&gt;download_path = export_item.download(BACKUP_DIR)&lt;BR /&gt;print(f"Downloaded backup to: {download_path}")&lt;/P&gt;&lt;P&gt;# Delete the temporary export item from AGOL content&lt;BR /&gt;export_item.delete()&lt;BR /&gt;print("Temporary export item deleted from ArcGIS Online.")&lt;BR /&gt;print("Backup process complete.")&lt;BR /&gt;Layer 'King George BMPs' not found.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Dec 2025 19:44:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/script-unable-to-locate-ago-layer-by-title/m-p/1671371#M11809</guid>
      <dc:creator>KyleConboy</dc:creator>
      <dc:date>2025-12-08T19:44:35Z</dc:date>
    </item>
    <item>
      <title>Re: script unable to locate AGO layer by title</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/script-unable-to-locate-ago-layer-by-title/m-p/1671916#M11810</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/67921"&gt;@KyleConboy&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;If you know which Feature Service you are backing up I would not use search() instead I would use get() and supply in the item id.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;search_result = gis.content.get("FS_ITEM_ID")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You can get the Item id from the URL of the Feature Service page and paste it in.&lt;/P&gt;&lt;P&gt;Let me know how you get on.&lt;/P&gt;&lt;P&gt;All the best,&lt;/P&gt;&lt;P&gt;Glen&lt;/P&gt;</description>
      <pubDate>Wed, 10 Dec 2025 10:18:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/script-unable-to-locate-ago-layer-by-title/m-p/1671916#M11810</guid>
      <dc:creator>Clubdebambos</dc:creator>
      <dc:date>2025-12-10T10:18:38Z</dc:date>
    </item>
    <item>
      <title>Re: script unable to locate AGO layer by title</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/script-unable-to-locate-ago-layer-by-title/m-p/1673014#M11816</link>
      <description>&lt;P&gt;Hi Glen,&lt;/P&gt;&lt;P&gt;Thanks for the response.&amp;nbsp; i now get this error:&lt;/P&gt;&lt;P&gt;# coding: utf-8&lt;/P&gt;&lt;P&gt;# coding: utf-8&lt;/P&gt;&lt;P&gt;from arcgis.gis import GIS&lt;/P&gt;&lt;P&gt;import os&lt;/P&gt;&lt;P&gt;import datetime&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;# --- Configuration ---&lt;/P&gt;&lt;P&gt;AGOL_ORG_URL = "&lt;A href="https://Org-name.maps.arcgis.com" target="_blank"&gt;https://Org-name.maps.arcgis.com&lt;/A&gt;"&lt;/P&gt;&lt;P&gt;USERNAME = "Username"&lt;/P&gt;&lt;P&gt;PASSWORD = "Password"&amp;nbsp;&lt;/P&gt;&lt;P&gt;BACKUP_DIR = r"directory" # Local directory for backups&lt;/P&gt;&lt;P&gt;LAYER_TITLE = "LayerTitle" # Title of the layer to backup&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;# Ensure backup directory exists&lt;/P&gt;&lt;P&gt;if not os.path.exists(BACKUP_DIR):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; os.makedirs(BACKUP_DIR)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;# Authenticate to ArcGIS Online&lt;/P&gt;&lt;P&gt;gis = GIS(AGOL_ORG_URL, USERNAME, PASSWORD)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;# Search for the hosted feature layer&lt;/P&gt;&lt;P&gt;# Note: You may need to refine the search query if the title isn't unique&lt;/P&gt;&lt;P&gt;search_result = gis.content.get("6b945b44045f4012853adbda211e81f8")&lt;/P&gt;&lt;P&gt;if not search_result:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; print(f"Layer '{LAYER_TITLE}' not found.")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; exit()&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;item = search_result[0]&lt;/P&gt;&lt;P&gt;print(f"Found item: {item.title}")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;# Export data to a File Geodatabase (FGDB) format&lt;/P&gt;&lt;P&gt;# This creates a new item in AGOL content, which will be deleted later&lt;/P&gt;&lt;P&gt;export_title = f"{item.title}_Backup_{datetime.datetime.now().strftime('%Y%m%d_%H%M%S')}"&lt;/P&gt;&lt;P&gt;export_item = item.export(export_title, "File Geodatabase", wait=True)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;# Download the exported file&lt;/P&gt;&lt;P&gt;download_path = export_item.download(BACKUP_DIR)&lt;/P&gt;&lt;P&gt;print(f"Downloaded backup to: {download_path}")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;# Delete the temporary export item from AGOL content&lt;/P&gt;&lt;P&gt;export_item.delete()&lt;/P&gt;&lt;P&gt;print("Temporary export item deleted from ArcGIS Online.")&lt;/P&gt;&lt;P&gt;print("Backup process complete.")&lt;/P&gt;&lt;P&gt;Traceback (most recent call last):&lt;/P&gt;&lt;P&gt;&amp;nbsp; File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\gis\__init__.py", line 14050, in __getitem__&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; return dict.__getitem__(self, k)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ^^^^^^^^^^^^^^^^^^^^^^^^^&lt;/P&gt;&lt;P&gt;KeyError: 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;During handling of the above exception, another exception occurred:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Traceback (most recent call last):&lt;/P&gt;&lt;P&gt;&amp;nbsp; File "&amp;lt;string&amp;gt;", line 28, in &amp;lt;module&amp;gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; File "C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\Lib\site-packages\arcgis\gis\__init__.py", line 14052, in __getitem__&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if not self._hydrated and not k.startswith("_"):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ^^^^^^^^^^^^&lt;/P&gt;&lt;P&gt;AttributeError: 'int' object has no attribute 'startswith'&lt;/P&gt;</description>
      <pubDate>Mon, 15 Dec 2025 14:57:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/script-unable-to-locate-ago-layer-by-title/m-p/1673014#M11816</guid>
      <dc:creator>KyleConboy</dc:creator>
      <dc:date>2025-12-15T14:57:42Z</dc:date>
    </item>
    <item>
      <title>Re: script unable to locate AGO layer by title</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/script-unable-to-locate-ago-layer-by-title/m-p/1673569#M11821</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/67921"&gt;@KyleConboy&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;The get() method does not return a list like search() does, so remove the [0] for item = search_result[0], you can just set the &lt;EM&gt;item&lt;/EM&gt; variable as per below...&lt;/P&gt;&lt;LI-CODE lang="python"&gt;item = gis.content.get("6b945b44045f4012853adbda211e81f8")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;No need for...&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;if not search_result:
    print(f"Layer '{LAYER_TITLE}' not found.")
    exit()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You could replace for something like...&lt;/P&gt;&lt;LI-CODE lang="python"&gt;if not item:
    print("Item not found") # this would only happen if the item id belonged to a different AGOL/Portal or was entered incorrectly

else:
    # continue with the workflow&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All the best,&lt;/P&gt;&lt;P&gt;Glen&lt;/P&gt;</description>
      <pubDate>Wed, 17 Dec 2025 13:15:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/script-unable-to-locate-ago-layer-by-title/m-p/1673569#M11821</guid>
      <dc:creator>Clubdebambos</dc:creator>
      <dc:date>2025-12-17T13:15:50Z</dc:date>
    </item>
  </channel>
</rss>

