<?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 Notebook failing randomly... or not? in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/notebook-failing-randomly-or-not/m-p/1392973#M10611</link>
    <description>&lt;P&gt;I have a notebook, the purpose of which is to calculate the intersections of several feature layers with another layer, and then store the results in tables particular to each layer. I've attached the Notebook to this post. What's odd is that for the most part, it works. But what seemed to be randomly (until lately when it fails all the time) it would fail with the error:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;Exception&lt;/SPAN&gt;: Item 'ZonePercentages.csv' already exists.
(Error Code: 409)&lt;/PRE&gt;&lt;P&gt;This is not an error it used to throw. The Notebook is written to delete all the files it creates when it is done, so no files should exist when it starts.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;My assumption ... my assumption when ever anything breaks ... is that I have a typo somewhere. However, two of us here have looked at this and can't figure out why it is doing this. And like I said, it just used to work.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tested clearing the directory before starting the script, and it still throws that error. I was wondering if anyone can spot any glaring errors.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Notebook starts here (forum software complained when I tried to attach it below as either .py or .txt):&lt;/P&gt;&lt;P&gt;#!/usr/bin/env python&lt;BR /&gt;# coding: utf-8&lt;/P&gt;&lt;P&gt;# ## Welcome to your notebook.&lt;BR /&gt;#&lt;/P&gt;&lt;P&gt;# #### Run this cell to connect to your GIS and get started:&lt;/P&gt;&lt;P&gt;# In[20]:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;from arcgis.gis import GIS&lt;BR /&gt;import arcgis&lt;BR /&gt;import arcpy&lt;BR /&gt;import os&lt;BR /&gt;import shutil&lt;/P&gt;&lt;P&gt;gis = GIS("home")&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# In[21]:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;def delete():&lt;BR /&gt;&amp;nbsp;for f in os.listdir(directory):&lt;BR /&gt;&amp;nbsp; if ".snapshot" not in f and ".tasks" not in f:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; if os.path.isfile(os.path.join(directory, f)):&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; os.remove(os.path.join(directory, f))&lt;BR /&gt;&amp;nbsp; &amp;nbsp; elif os.path.isdir(os.path.join(directory, f)):&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; shutil.rmtree(os.path.join(directory, f))&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# #### Now you are ready to start!&lt;/P&gt;&lt;P&gt;# In[22]:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;directory = "/arcgis/home/"&lt;BR /&gt;parcels_shp = os.path.join(directory, "parcels")&lt;BR /&gt;zones_shp = os.path.join(directory, "zones")&lt;BR /&gt;fsa_shp = os.path.join(directory, "fsa")&lt;BR /&gt;sra_shp = os.path.join(directory, "sra")&lt;BR /&gt;fz_shp = os.path.join(directory, "floodzones")&lt;BR /&gt;cp_shp = os.path.join(directory, "compPlan")&lt;BR /&gt;pd_shp = os.path.join(directory, "planDist")&lt;BR /&gt;ub_shp = os.path.join(directory, "urbanBoundary")&lt;BR /&gt;rd_shp = os.path.join(directory, "roadDist")&lt;BR /&gt;rsa_shp = os.path.join(directory, "rsa")&lt;BR /&gt;zone_csv = os.path.join(directory, "ZonePercentages.csv")&lt;BR /&gt;fsa_csv = os.path.join(directory, "fsa.csv")&lt;BR /&gt;sra_csv = os.path.join(directory, "sra.csv")&lt;BR /&gt;fz_csv = os.path.join(directory, "FloodZonePercentages.csv")&lt;BR /&gt;cp_csv = os.path.join(directory, "ComPlanPercentages.csv")&lt;BR /&gt;pd_csv = os.path.join(directory, "planningDistrictPercentages.csv")&lt;BR /&gt;ub_csv = os.path.join(directory, "urbanBoundaryPercentages.csv")&lt;BR /&gt;rd_csv = os.path.join(directory, "roadDistrictPercentages.csv")&lt;BR /&gt;rsa_csv = os.path.join(directory, "roadServiceAreaPercentages.csv")&lt;BR /&gt;delete()&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# In[23]:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;parcels = arcgis.features.FeatureLayer("&lt;A href="https://gisportal.fnsb.gov/referenced/rest/services/_/Parcels_with_TaxInfo/FeatureServer/1" target="_blank" rel="noopener"&gt;https://gisportal.fnsb.gov/referenced/rest/services/_/Parcels_with_TaxInfo/FeatureServer/1&lt;/A&gt;").query().sdf[["PAN", "SHAPE"]]&lt;BR /&gt;parcels.drop(parcels[parcels["PAN"] == 9999999].index, inplace=True)&lt;BR /&gt;parcels.drop(parcels[parcels["PAN"] == 999999].index, inplace=True)&lt;BR /&gt;zones = arcgis.features.FeatureLayer("&lt;A href="https://gisportal.fnsb.gov/referenced/rest/services/_/Zoning_Districts/FeatureServer/1" target="_blank" rel="noopener"&gt;https://gisportal.fnsb.gov/referenced/rest/services/_/Zoning_Districts/FeatureServer/1&lt;/A&gt;").query().sdf[["ZONE", "ZONE_DESC", "SHAPE"]]&lt;BR /&gt;fsa = arcgis.features.FeatureLayer("&lt;A href="https://gisportal.fnsb.gov/referenced/rest/services/_/Fire_Service_Areas/FeatureServer/1" target="_blank" rel="noopener"&gt;https://gisportal.fnsb.gov/referenced/rest/services/_/Fire_Service_Areas/FeatureServer/1&lt;/A&gt;").query().sdf[["NAME", "SHAPE"]]&lt;BR /&gt;sra = arcgis.features.FeatureLayer("&lt;A href="https://services.arcgis.com/f4rR7WnIfGBdVYFd/ArcGIS/rest/services/Special_Regulatory_Areas/FeatureServer/98" target="_blank" rel="noopener"&gt;https://services.arcgis.com/f4rR7WnIfGBdVYFd/ArcGIS/rest/services/Special_Regulatory_Areas/FeatureServer/98&lt;/A&gt;").query().sdf[["TYPE", "NOTES", "SHAPE"]]&lt;BR /&gt;floodZones = arcgis.features.FeatureLayer("&lt;A href="https://services.arcgis.com/f4rR7WnIfGBdVYFd/ArcGIS/rest/services/National_Flood_Hazards_Layer_-_State_of_Alaska_-_FNSB/FeatureServer/9" target="_blank" rel="noopener"&gt;https://services.arcgis.com/f4rR7WnIfGBdVYFd/ArcGIS/rest/services/National_Flood_Hazards_Layer_-_State_of_Alaska_-_FNSB/FeatureServer/9&lt;/A&gt;").query(where = "DFIRM_ID='02090C'").sdf[["FLD_ZONE", "ZONE_SUBTY", "SHAPE"]]&lt;BR /&gt;compPlans = arcgis.features.FeatureLayer("&lt;A href="https://services.arcgis.com/f4rR7WnIfGBdVYFd/ArcGIS/rest/services/Comprehensive_Plan/FeatureServer/103" target="_blank" rel="noopener"&gt;https://services.arcgis.com/f4rR7WnIfGBdVYFd/ArcGIS/rest/services/Comprehensive_Plan/FeatureServer/103&lt;/A&gt;").query().sdf[["NAME", "SHAPE"]]&lt;BR /&gt;planDist = arcgis.features.FeatureLayer("&lt;A href="https://services.arcgis.com/f4rR7WnIfGBdVYFd/ArcGIS/rest/services/Planning_Districts/FeatureServer/2" target="_blank" rel="noopener"&gt;https://services.arcgis.com/f4rR7WnIfGBdVYFd/ArcGIS/rest/services/Planning_Districts/FeatureServer/2&lt;/A&gt;").query().sdf[["NAME", "SHAPE"]]&lt;BR /&gt;urbanBound = arcgis.features.FeatureLayer("&lt;A href="https://services.arcgis.com/f4rR7WnIfGBdVYFd/ArcGIS/rest/services/Census_2020_Urban_Boundary/FeatureServer/228" target="_blank" rel="noopener"&gt;https://services.arcgis.com/f4rR7WnIfGBdVYFd/ArcGIS/rest/services/Census_2020_Urban_Boundary/FeatureServer/228&lt;/A&gt;").query().sdf[["NAME20", "SHAPE"]]&lt;BR /&gt;roadDist = arcgis.features.FeatureLayer("&lt;A href="https://services.arcgis.com/f4rR7WnIfGBdVYFd/ArcGIS/rest/services/Road_Districts/FeatureServer/3" target="_blank" rel="noopener"&gt;https://services.arcgis.com/f4rR7WnIfGBdVYFd/ArcGIS/rest/services/Road_Districts/FeatureServer/3&lt;/A&gt;").query().sdf[["NAME", "DIST_NUM", "SHAPE"]]&lt;BR /&gt;rsa = arcgis.features.FeatureLayer("&lt;A href="https://gisportal.fnsb.gov/referenced/rest/services/_/Road_Service_Areas/FeatureServer/1" target="_blank" rel="noopener"&gt;https://gisportal.fnsb.gov/referenced/rest/services/_/Road_Service_Areas/FeatureServer/1&lt;/A&gt;").query().sdf[["NAME", "SHAPE"]]&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# In[24]:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;parcels = parcels.spatial.to_featureclass(parcels_shp)&lt;BR /&gt;zones = zones.spatial.to_featureclass(zones_shp)&lt;BR /&gt;fsa = fsa.spatial.to_featureclass(fsa_shp)&lt;BR /&gt;sra = sra.spatial.to_featureclass(sra_shp)&lt;BR /&gt;floodZones = floodZones.spatial.to_featureclass(fz_shp)&lt;BR /&gt;compPlans = compPlans.spatial.to_featureclass(cp_shp)&lt;BR /&gt;planDist = planDist.spatial.to_featureclass(pd_shp)&lt;BR /&gt;urbanBound = urbanBound.spatial.to_featureclass(ub_shp)&lt;BR /&gt;roadDist = roadDist.spatial.to_featureclass(rd_shp)&lt;BR /&gt;rsa = rsa.spatial.to_featureclass(rsa_shp)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# In[25]:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;zone_percentages = arcpy.analysis.TabulateIntersection(parcels, "PAN", zones, zone_csv, ["ZONE", "ZONE_DESC"], out_units="ACRES")&lt;BR /&gt;fsa_percentages = arcpy.analysis.TabulateIntersection(parcels, "PAN", fsa, fsa_csv, ["NAME"], out_units="ACRES")&lt;BR /&gt;sra_percentages = arcpy.analysis.TabulateIntersection(parcels, "PAN", sra, sra_csv, ["AREATYPE", "NOTES"], out_units="ACRES")&lt;BR /&gt;floodZone_percentages = arcpy.analysis.TabulateIntersection(parcels, "PAN", floodZones, fz_csv, ["FLD_ZONE", "ZONE_SUBTY"], out_units="ACRES")&lt;BR /&gt;compPlan_percentages = arcpy.analysis.TabulateIntersection(parcels, "PAN", compPlans, cp_csv, ["NAME"], out_units = "ACRES")&lt;BR /&gt;planDist_percentages = arcpy.analysis.TabulateIntersection(parcels, "PAN", planDist, pd_csv, ["NAME"], out_units = "ACRES")&lt;BR /&gt;urbanBound_percentages = arcpy.analysis.TabulateIntersection(parcels, "PAN", urbanBound, ub_csv, ["NAME20"], out_units = "ACRES")&lt;BR /&gt;roadDist_percentages = arcpy.analysis.TabulateIntersection(parcels, "PAN", roadDist, rd_csv, ["NAME", "DIST_NUM"], out_units = "ACRES")&lt;BR /&gt;rsa_percentages = arcpy.analysis.TabulateIntersection(parcels, "PAN", rsa, rsa_csv, ["NAME"], out_units="ACRES")&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# In[26]:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;item_properties = {"title": "temp"}&lt;BR /&gt;folder = "Parcel Overlap Calculations"&lt;BR /&gt;zone_percentages_item = gis.content.add(item_properties, zone_csv, folder=folder)&lt;BR /&gt;fsa_percentages_item = gis.content.add(item_properties, fsa_csv, folder=folder)&lt;BR /&gt;sra_percentages_item = gis.content.add(item_properties, sra_csv, folder=folder)&lt;BR /&gt;floodZone_percentages_item = gis.content.add(item_properties, fz_csv, folder=folder)&lt;BR /&gt;compPlan_percentage_item = gis.content.add(item_properties, cp_csv, folder=folder)&lt;BR /&gt;planDist_percentage_item = gis.content.add(item_properties, pd_csv, folder=folder)&lt;BR /&gt;urbanBound_percentage_item = gis.content.add(item_properties, ub_csv, folder=folder)&lt;BR /&gt;roadDist_percentage_item = gis.content.add(item_properties, rd_csv, folder=folder)&lt;BR /&gt;rsa_percentage_item = gis.content.add(item_properties, rsa_csv, folder=folder)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# In[27]:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;zones_fl = arcgis.features.FeatureLayer("&lt;A href="https://services.arcgis.com/f4rR7WnIfGBdVYFd/arcgis/rest/services/Zone_Percentages/FeatureServer/0" target="_blank" rel="noopener"&gt;https://services.arcgis.com/f4rR7WnIfGBdVYFd/arcgis/rest/services/Zone_Percentages/FeatureServer/0&lt;/A&gt;")&lt;BR /&gt;fsa_fl = arcgis.features.FeatureLayer("&lt;A href="https://services.arcgis.com/f4rR7WnIfGBdVYFd/ArcGIS/rest/services/FireServiceAreas/FeatureServer/0" target="_blank" rel="noopener"&gt;https://services.arcgis.com/f4rR7WnIfGBdVYFd/ArcGIS/rest/services/FireServiceAreas/FeatureServer/0&lt;/A&gt;")&lt;BR /&gt;sra_fl = arcgis.features.FeatureLayer("&lt;A href="https://services.arcgis.com/f4rR7WnIfGBdVYFd/arcgis/rest/services/SpecialRegAreas/FeatureServer/0" target="_blank" rel="noopener"&gt;https://services.arcgis.com/f4rR7WnIfGBdVYFd/arcgis/rest/services/SpecialRegAreas/FeatureServer/0&lt;/A&gt;")&lt;BR /&gt;fz_fl = arcgis.features.FeatureLayer("&lt;A href="https://services.arcgis.com/f4rR7WnIfGBdVYFd/ArcGIS/rest/services/FloodZonePercentages/FeatureServer/0" target="_blank" rel="noopener"&gt;https://services.arcgis.com/f4rR7WnIfGBdVYFd/ArcGIS/rest/services/FloodZonePercentages/FeatureServer/0&lt;/A&gt;")&lt;BR /&gt;cp_fl = arcgis.features.FeatureLayer("&lt;A href="https://services.arcgis.com/f4rR7WnIfGBdVYFd/ArcGIS/rest/services/ComPlanPercentages/FeatureServer/0" target="_blank" rel="noopener"&gt;https://services.arcgis.com/f4rR7WnIfGBdVYFd/ArcGIS/rest/services/ComPlanPercentages/FeatureServer/0&lt;/A&gt;")&lt;BR /&gt;pd_fl = arcgis.features.FeatureLayer("&lt;A href="https://services.arcgis.com/f4rR7WnIfGBdVYFd/arcgis/rest/services/PlanningDistrictPercentages/FeatureServer/0" target="_blank" rel="noopener"&gt;https://services.arcgis.com/f4rR7WnIfGBdVYFd/arcgis/rest/services/PlanningDistrictPercentages/FeatureServer/0&lt;/A&gt;")&lt;BR /&gt;ub_fl = arcgis.features.FeatureLayer("&lt;A href="https://services.arcgis.com/f4rR7WnIfGBdVYFd/arcgis/rest/services/UrbanBoundaryPercentages/FeatureServer/0" target="_blank" rel="noopener"&gt;https://services.arcgis.com/f4rR7WnIfGBdVYFd/arcgis/rest/services/UrbanBoundaryPercentages/FeatureServer/0&lt;/A&gt;")&lt;BR /&gt;rd_fl = arcgis.features.FeatureLayer("&lt;A href="https://services.arcgis.com/f4rR7WnIfGBdVYFd/ArcGIS/rest/services/RoadDistricPercentages/FeatureServer/0" target="_blank" rel="noopener"&gt;https://services.arcgis.com/f4rR7WnIfGBdVYFd/ArcGIS/rest/services/RoadDistricPercentages/FeatureServer/0&lt;/A&gt;")&lt;BR /&gt;rsa_fl = arcgis.features.FeatureLayer("&lt;A href="https://services.arcgis.com/f4rR7WnIfGBdVYFd/ArcGIS/rest/services/RoadServiceAreaPercentages/FeatureServer/0" target="_blank" rel="noopener"&gt;https://services.arcgis.com/f4rR7WnIfGBdVYFd/ArcGIS/rest/services/RoadServiceAreaPercentages/FeatureServer/0&lt;/A&gt;")&lt;BR /&gt;zones_fl.manager.truncate()&lt;BR /&gt;fsa_fl.manager.truncate()&lt;BR /&gt;sra_fl.manager.truncate()&lt;BR /&gt;fz_fl.manager.truncate()&lt;BR /&gt;cp_fl.manager.truncate()&lt;BR /&gt;pd_fl.manager.truncate()&lt;BR /&gt;ub_fl.manager.truncate()&lt;BR /&gt;rd_fl.manager.truncate()&lt;BR /&gt;rsa_fl.manager.truncate()&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# In[36]:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;zones_fl.append(item_id = zone_percentages_item.itemid, upload_format = "csv", source_table_name = "ZonePercentages", source_info = gis.content.analyze(item = zone_percentages_item.itemid))&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# In[37]:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;fsa_fl.append(item_id = fsa_percentages_item.itemid, upload_format="csv", source_table_name="FireServiceAreaPercentages", source_info = gis.content.analyze(item = fsa_percentages_item.itemid))&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# In[38]:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;sra_fl.append(item_id = sra_percentages_item.itemid, upload_format = "csv", source_table_name = "SpecialRegAreas", source_info = gis.content.analyze(item = sra_percentages_item.itemid))&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# In[39]:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;fz_fl.append(item_id = floodZone_percentages_item.itemid, upload_format = "csv", source_table_name = "FloodZonePercentages", source_info = gis.content.analyze(item = floodZone_percentages_item.itemid))&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# In[40]:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;cp_fl.append(item_id = compPlan_percentage_item.itemid, upload_format = "csv", source_table_name = "ComPlanPercentages", source_info = gis.content.analyze(item = compPlan_percentage_item.itemid))&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# In[41]:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;pd_fl.append(item_id = planDist_percentage_item.itemid, upload_format = "csv", source_table_name = "PlanningDistrictPercentages", source_info = gis.content.analyze(item = planDist_percentage_item.itemid))&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# In[42]:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;ub_fl.append(item_id = urbanBound_percentage_item.itemid, upload_format = "csv", source_table_name = "UrbanBoundaryPercentages", source_info = gis.content.analyze(item = urbanBound_percentage_item.itemid))&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# In[43]:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;rd_fl.append(item_id = roadDist_percentage_item.itemid, upload_format = "csv", source_table_name = "RoadDistrictPercentages", source_info = gis.content.analyze(item = roadDist_percentage_item.itemid))&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# In[44]:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;rsa_fl.append(item_id = rsa_percentage_item.itemid, upload_format = "csv", source_table_name = "RoadServiceAreaPercentages", source_info = gis.content.analyze(item = rsa_percentage_item.itemid))&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# In[45]:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;csv_items = [&lt;BR /&gt;zone_percentages_item&lt;BR /&gt;, fsa_percentages_item&lt;BR /&gt;, sra_percentages_item&lt;BR /&gt;, floodZone_percentages_item&lt;BR /&gt;, compPlan_percentage_item&lt;BR /&gt;, planDist_percentage_item&lt;BR /&gt;, urbanBound_percentage_item&lt;BR /&gt;, roadDist_percentage_item&lt;BR /&gt;, rsa_percentage_item&lt;BR /&gt;]&lt;/P&gt;&lt;P&gt;for i in csv_items:&lt;BR /&gt;print(i)&lt;BR /&gt;try:&lt;BR /&gt;i.delete()&lt;BR /&gt;except Exception as e:&lt;BR /&gt;print(e)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# In[46]:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;delete()&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# In[ ]:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 08 Mar 2024 00:37:15 GMT</pubDate>
    <dc:creator>RogerAsbury</dc:creator>
    <dc:date>2024-03-08T00:37:15Z</dc:date>
    <item>
      <title>Notebook failing randomly... or not?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/notebook-failing-randomly-or-not/m-p/1392973#M10611</link>
      <description>&lt;P&gt;I have a notebook, the purpose of which is to calculate the intersections of several feature layers with another layer, and then store the results in tables particular to each layer. I've attached the Notebook to this post. What's odd is that for the most part, it works. But what seemed to be randomly (until lately when it fails all the time) it would fail with the error:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;Exception&lt;/SPAN&gt;: Item 'ZonePercentages.csv' already exists.
(Error Code: 409)&lt;/PRE&gt;&lt;P&gt;This is not an error it used to throw. The Notebook is written to delete all the files it creates when it is done, so no files should exist when it starts.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;My assumption ... my assumption when ever anything breaks ... is that I have a typo somewhere. However, two of us here have looked at this and can't figure out why it is doing this. And like I said, it just used to work.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tested clearing the directory before starting the script, and it still throws that error. I was wondering if anyone can spot any glaring errors.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Notebook starts here (forum software complained when I tried to attach it below as either .py or .txt):&lt;/P&gt;&lt;P&gt;#!/usr/bin/env python&lt;BR /&gt;# coding: utf-8&lt;/P&gt;&lt;P&gt;# ## Welcome to your notebook.&lt;BR /&gt;#&lt;/P&gt;&lt;P&gt;# #### Run this cell to connect to your GIS and get started:&lt;/P&gt;&lt;P&gt;# In[20]:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;from arcgis.gis import GIS&lt;BR /&gt;import arcgis&lt;BR /&gt;import arcpy&lt;BR /&gt;import os&lt;BR /&gt;import shutil&lt;/P&gt;&lt;P&gt;gis = GIS("home")&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# In[21]:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;def delete():&lt;BR /&gt;&amp;nbsp;for f in os.listdir(directory):&lt;BR /&gt;&amp;nbsp; if ".snapshot" not in f and ".tasks" not in f:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; if os.path.isfile(os.path.join(directory, f)):&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; os.remove(os.path.join(directory, f))&lt;BR /&gt;&amp;nbsp; &amp;nbsp; elif os.path.isdir(os.path.join(directory, f)):&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; shutil.rmtree(os.path.join(directory, f))&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# #### Now you are ready to start!&lt;/P&gt;&lt;P&gt;# In[22]:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;directory = "/arcgis/home/"&lt;BR /&gt;parcels_shp = os.path.join(directory, "parcels")&lt;BR /&gt;zones_shp = os.path.join(directory, "zones")&lt;BR /&gt;fsa_shp = os.path.join(directory, "fsa")&lt;BR /&gt;sra_shp = os.path.join(directory, "sra")&lt;BR /&gt;fz_shp = os.path.join(directory, "floodzones")&lt;BR /&gt;cp_shp = os.path.join(directory, "compPlan")&lt;BR /&gt;pd_shp = os.path.join(directory, "planDist")&lt;BR /&gt;ub_shp = os.path.join(directory, "urbanBoundary")&lt;BR /&gt;rd_shp = os.path.join(directory, "roadDist")&lt;BR /&gt;rsa_shp = os.path.join(directory, "rsa")&lt;BR /&gt;zone_csv = os.path.join(directory, "ZonePercentages.csv")&lt;BR /&gt;fsa_csv = os.path.join(directory, "fsa.csv")&lt;BR /&gt;sra_csv = os.path.join(directory, "sra.csv")&lt;BR /&gt;fz_csv = os.path.join(directory, "FloodZonePercentages.csv")&lt;BR /&gt;cp_csv = os.path.join(directory, "ComPlanPercentages.csv")&lt;BR /&gt;pd_csv = os.path.join(directory, "planningDistrictPercentages.csv")&lt;BR /&gt;ub_csv = os.path.join(directory, "urbanBoundaryPercentages.csv")&lt;BR /&gt;rd_csv = os.path.join(directory, "roadDistrictPercentages.csv")&lt;BR /&gt;rsa_csv = os.path.join(directory, "roadServiceAreaPercentages.csv")&lt;BR /&gt;delete()&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# In[23]:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;parcels = arcgis.features.FeatureLayer("&lt;A href="https://gisportal.fnsb.gov/referenced/rest/services/_/Parcels_with_TaxInfo/FeatureServer/1" target="_blank" rel="noopener"&gt;https://gisportal.fnsb.gov/referenced/rest/services/_/Parcels_with_TaxInfo/FeatureServer/1&lt;/A&gt;").query().sdf[["PAN", "SHAPE"]]&lt;BR /&gt;parcels.drop(parcels[parcels["PAN"] == 9999999].index, inplace=True)&lt;BR /&gt;parcels.drop(parcels[parcels["PAN"] == 999999].index, inplace=True)&lt;BR /&gt;zones = arcgis.features.FeatureLayer("&lt;A href="https://gisportal.fnsb.gov/referenced/rest/services/_/Zoning_Districts/FeatureServer/1" target="_blank" rel="noopener"&gt;https://gisportal.fnsb.gov/referenced/rest/services/_/Zoning_Districts/FeatureServer/1&lt;/A&gt;").query().sdf[["ZONE", "ZONE_DESC", "SHAPE"]]&lt;BR /&gt;fsa = arcgis.features.FeatureLayer("&lt;A href="https://gisportal.fnsb.gov/referenced/rest/services/_/Fire_Service_Areas/FeatureServer/1" target="_blank" rel="noopener"&gt;https://gisportal.fnsb.gov/referenced/rest/services/_/Fire_Service_Areas/FeatureServer/1&lt;/A&gt;").query().sdf[["NAME", "SHAPE"]]&lt;BR /&gt;sra = arcgis.features.FeatureLayer("&lt;A href="https://services.arcgis.com/f4rR7WnIfGBdVYFd/ArcGIS/rest/services/Special_Regulatory_Areas/FeatureServer/98" target="_blank" rel="noopener"&gt;https://services.arcgis.com/f4rR7WnIfGBdVYFd/ArcGIS/rest/services/Special_Regulatory_Areas/FeatureServer/98&lt;/A&gt;").query().sdf[["TYPE", "NOTES", "SHAPE"]]&lt;BR /&gt;floodZones = arcgis.features.FeatureLayer("&lt;A href="https://services.arcgis.com/f4rR7WnIfGBdVYFd/ArcGIS/rest/services/National_Flood_Hazards_Layer_-_State_of_Alaska_-_FNSB/FeatureServer/9" target="_blank" rel="noopener"&gt;https://services.arcgis.com/f4rR7WnIfGBdVYFd/ArcGIS/rest/services/National_Flood_Hazards_Layer_-_State_of_Alaska_-_FNSB/FeatureServer/9&lt;/A&gt;").query(where = "DFIRM_ID='02090C'").sdf[["FLD_ZONE", "ZONE_SUBTY", "SHAPE"]]&lt;BR /&gt;compPlans = arcgis.features.FeatureLayer("&lt;A href="https://services.arcgis.com/f4rR7WnIfGBdVYFd/ArcGIS/rest/services/Comprehensive_Plan/FeatureServer/103" target="_blank" rel="noopener"&gt;https://services.arcgis.com/f4rR7WnIfGBdVYFd/ArcGIS/rest/services/Comprehensive_Plan/FeatureServer/103&lt;/A&gt;").query().sdf[["NAME", "SHAPE"]]&lt;BR /&gt;planDist = arcgis.features.FeatureLayer("&lt;A href="https://services.arcgis.com/f4rR7WnIfGBdVYFd/ArcGIS/rest/services/Planning_Districts/FeatureServer/2" target="_blank" rel="noopener"&gt;https://services.arcgis.com/f4rR7WnIfGBdVYFd/ArcGIS/rest/services/Planning_Districts/FeatureServer/2&lt;/A&gt;").query().sdf[["NAME", "SHAPE"]]&lt;BR /&gt;urbanBound = arcgis.features.FeatureLayer("&lt;A href="https://services.arcgis.com/f4rR7WnIfGBdVYFd/ArcGIS/rest/services/Census_2020_Urban_Boundary/FeatureServer/228" target="_blank" rel="noopener"&gt;https://services.arcgis.com/f4rR7WnIfGBdVYFd/ArcGIS/rest/services/Census_2020_Urban_Boundary/FeatureServer/228&lt;/A&gt;").query().sdf[["NAME20", "SHAPE"]]&lt;BR /&gt;roadDist = arcgis.features.FeatureLayer("&lt;A href="https://services.arcgis.com/f4rR7WnIfGBdVYFd/ArcGIS/rest/services/Road_Districts/FeatureServer/3" target="_blank" rel="noopener"&gt;https://services.arcgis.com/f4rR7WnIfGBdVYFd/ArcGIS/rest/services/Road_Districts/FeatureServer/3&lt;/A&gt;").query().sdf[["NAME", "DIST_NUM", "SHAPE"]]&lt;BR /&gt;rsa = arcgis.features.FeatureLayer("&lt;A href="https://gisportal.fnsb.gov/referenced/rest/services/_/Road_Service_Areas/FeatureServer/1" target="_blank" rel="noopener"&gt;https://gisportal.fnsb.gov/referenced/rest/services/_/Road_Service_Areas/FeatureServer/1&lt;/A&gt;").query().sdf[["NAME", "SHAPE"]]&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# In[24]:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;parcels = parcels.spatial.to_featureclass(parcels_shp)&lt;BR /&gt;zones = zones.spatial.to_featureclass(zones_shp)&lt;BR /&gt;fsa = fsa.spatial.to_featureclass(fsa_shp)&lt;BR /&gt;sra = sra.spatial.to_featureclass(sra_shp)&lt;BR /&gt;floodZones = floodZones.spatial.to_featureclass(fz_shp)&lt;BR /&gt;compPlans = compPlans.spatial.to_featureclass(cp_shp)&lt;BR /&gt;planDist = planDist.spatial.to_featureclass(pd_shp)&lt;BR /&gt;urbanBound = urbanBound.spatial.to_featureclass(ub_shp)&lt;BR /&gt;roadDist = roadDist.spatial.to_featureclass(rd_shp)&lt;BR /&gt;rsa = rsa.spatial.to_featureclass(rsa_shp)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# In[25]:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;zone_percentages = arcpy.analysis.TabulateIntersection(parcels, "PAN", zones, zone_csv, ["ZONE", "ZONE_DESC"], out_units="ACRES")&lt;BR /&gt;fsa_percentages = arcpy.analysis.TabulateIntersection(parcels, "PAN", fsa, fsa_csv, ["NAME"], out_units="ACRES")&lt;BR /&gt;sra_percentages = arcpy.analysis.TabulateIntersection(parcels, "PAN", sra, sra_csv, ["AREATYPE", "NOTES"], out_units="ACRES")&lt;BR /&gt;floodZone_percentages = arcpy.analysis.TabulateIntersection(parcels, "PAN", floodZones, fz_csv, ["FLD_ZONE", "ZONE_SUBTY"], out_units="ACRES")&lt;BR /&gt;compPlan_percentages = arcpy.analysis.TabulateIntersection(parcels, "PAN", compPlans, cp_csv, ["NAME"], out_units = "ACRES")&lt;BR /&gt;planDist_percentages = arcpy.analysis.TabulateIntersection(parcels, "PAN", planDist, pd_csv, ["NAME"], out_units = "ACRES")&lt;BR /&gt;urbanBound_percentages = arcpy.analysis.TabulateIntersection(parcels, "PAN", urbanBound, ub_csv, ["NAME20"], out_units = "ACRES")&lt;BR /&gt;roadDist_percentages = arcpy.analysis.TabulateIntersection(parcels, "PAN", roadDist, rd_csv, ["NAME", "DIST_NUM"], out_units = "ACRES")&lt;BR /&gt;rsa_percentages = arcpy.analysis.TabulateIntersection(parcels, "PAN", rsa, rsa_csv, ["NAME"], out_units="ACRES")&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# In[26]:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;item_properties = {"title": "temp"}&lt;BR /&gt;folder = "Parcel Overlap Calculations"&lt;BR /&gt;zone_percentages_item = gis.content.add(item_properties, zone_csv, folder=folder)&lt;BR /&gt;fsa_percentages_item = gis.content.add(item_properties, fsa_csv, folder=folder)&lt;BR /&gt;sra_percentages_item = gis.content.add(item_properties, sra_csv, folder=folder)&lt;BR /&gt;floodZone_percentages_item = gis.content.add(item_properties, fz_csv, folder=folder)&lt;BR /&gt;compPlan_percentage_item = gis.content.add(item_properties, cp_csv, folder=folder)&lt;BR /&gt;planDist_percentage_item = gis.content.add(item_properties, pd_csv, folder=folder)&lt;BR /&gt;urbanBound_percentage_item = gis.content.add(item_properties, ub_csv, folder=folder)&lt;BR /&gt;roadDist_percentage_item = gis.content.add(item_properties, rd_csv, folder=folder)&lt;BR /&gt;rsa_percentage_item = gis.content.add(item_properties, rsa_csv, folder=folder)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# In[27]:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;zones_fl = arcgis.features.FeatureLayer("&lt;A href="https://services.arcgis.com/f4rR7WnIfGBdVYFd/arcgis/rest/services/Zone_Percentages/FeatureServer/0" target="_blank" rel="noopener"&gt;https://services.arcgis.com/f4rR7WnIfGBdVYFd/arcgis/rest/services/Zone_Percentages/FeatureServer/0&lt;/A&gt;")&lt;BR /&gt;fsa_fl = arcgis.features.FeatureLayer("&lt;A href="https://services.arcgis.com/f4rR7WnIfGBdVYFd/ArcGIS/rest/services/FireServiceAreas/FeatureServer/0" target="_blank" rel="noopener"&gt;https://services.arcgis.com/f4rR7WnIfGBdVYFd/ArcGIS/rest/services/FireServiceAreas/FeatureServer/0&lt;/A&gt;")&lt;BR /&gt;sra_fl = arcgis.features.FeatureLayer("&lt;A href="https://services.arcgis.com/f4rR7WnIfGBdVYFd/arcgis/rest/services/SpecialRegAreas/FeatureServer/0" target="_blank" rel="noopener"&gt;https://services.arcgis.com/f4rR7WnIfGBdVYFd/arcgis/rest/services/SpecialRegAreas/FeatureServer/0&lt;/A&gt;")&lt;BR /&gt;fz_fl = arcgis.features.FeatureLayer("&lt;A href="https://services.arcgis.com/f4rR7WnIfGBdVYFd/ArcGIS/rest/services/FloodZonePercentages/FeatureServer/0" target="_blank" rel="noopener"&gt;https://services.arcgis.com/f4rR7WnIfGBdVYFd/ArcGIS/rest/services/FloodZonePercentages/FeatureServer/0&lt;/A&gt;")&lt;BR /&gt;cp_fl = arcgis.features.FeatureLayer("&lt;A href="https://services.arcgis.com/f4rR7WnIfGBdVYFd/ArcGIS/rest/services/ComPlanPercentages/FeatureServer/0" target="_blank" rel="noopener"&gt;https://services.arcgis.com/f4rR7WnIfGBdVYFd/ArcGIS/rest/services/ComPlanPercentages/FeatureServer/0&lt;/A&gt;")&lt;BR /&gt;pd_fl = arcgis.features.FeatureLayer("&lt;A href="https://services.arcgis.com/f4rR7WnIfGBdVYFd/arcgis/rest/services/PlanningDistrictPercentages/FeatureServer/0" target="_blank" rel="noopener"&gt;https://services.arcgis.com/f4rR7WnIfGBdVYFd/arcgis/rest/services/PlanningDistrictPercentages/FeatureServer/0&lt;/A&gt;")&lt;BR /&gt;ub_fl = arcgis.features.FeatureLayer("&lt;A href="https://services.arcgis.com/f4rR7WnIfGBdVYFd/arcgis/rest/services/UrbanBoundaryPercentages/FeatureServer/0" target="_blank" rel="noopener"&gt;https://services.arcgis.com/f4rR7WnIfGBdVYFd/arcgis/rest/services/UrbanBoundaryPercentages/FeatureServer/0&lt;/A&gt;")&lt;BR /&gt;rd_fl = arcgis.features.FeatureLayer("&lt;A href="https://services.arcgis.com/f4rR7WnIfGBdVYFd/ArcGIS/rest/services/RoadDistricPercentages/FeatureServer/0" target="_blank" rel="noopener"&gt;https://services.arcgis.com/f4rR7WnIfGBdVYFd/ArcGIS/rest/services/RoadDistricPercentages/FeatureServer/0&lt;/A&gt;")&lt;BR /&gt;rsa_fl = arcgis.features.FeatureLayer("&lt;A href="https://services.arcgis.com/f4rR7WnIfGBdVYFd/ArcGIS/rest/services/RoadServiceAreaPercentages/FeatureServer/0" target="_blank" rel="noopener"&gt;https://services.arcgis.com/f4rR7WnIfGBdVYFd/ArcGIS/rest/services/RoadServiceAreaPercentages/FeatureServer/0&lt;/A&gt;")&lt;BR /&gt;zones_fl.manager.truncate()&lt;BR /&gt;fsa_fl.manager.truncate()&lt;BR /&gt;sra_fl.manager.truncate()&lt;BR /&gt;fz_fl.manager.truncate()&lt;BR /&gt;cp_fl.manager.truncate()&lt;BR /&gt;pd_fl.manager.truncate()&lt;BR /&gt;ub_fl.manager.truncate()&lt;BR /&gt;rd_fl.manager.truncate()&lt;BR /&gt;rsa_fl.manager.truncate()&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# In[36]:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;zones_fl.append(item_id = zone_percentages_item.itemid, upload_format = "csv", source_table_name = "ZonePercentages", source_info = gis.content.analyze(item = zone_percentages_item.itemid))&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# In[37]:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;fsa_fl.append(item_id = fsa_percentages_item.itemid, upload_format="csv", source_table_name="FireServiceAreaPercentages", source_info = gis.content.analyze(item = fsa_percentages_item.itemid))&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# In[38]:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;sra_fl.append(item_id = sra_percentages_item.itemid, upload_format = "csv", source_table_name = "SpecialRegAreas", source_info = gis.content.analyze(item = sra_percentages_item.itemid))&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# In[39]:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;fz_fl.append(item_id = floodZone_percentages_item.itemid, upload_format = "csv", source_table_name = "FloodZonePercentages", source_info = gis.content.analyze(item = floodZone_percentages_item.itemid))&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# In[40]:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;cp_fl.append(item_id = compPlan_percentage_item.itemid, upload_format = "csv", source_table_name = "ComPlanPercentages", source_info = gis.content.analyze(item = compPlan_percentage_item.itemid))&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# In[41]:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;pd_fl.append(item_id = planDist_percentage_item.itemid, upload_format = "csv", source_table_name = "PlanningDistrictPercentages", source_info = gis.content.analyze(item = planDist_percentage_item.itemid))&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# In[42]:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;ub_fl.append(item_id = urbanBound_percentage_item.itemid, upload_format = "csv", source_table_name = "UrbanBoundaryPercentages", source_info = gis.content.analyze(item = urbanBound_percentage_item.itemid))&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# In[43]:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;rd_fl.append(item_id = roadDist_percentage_item.itemid, upload_format = "csv", source_table_name = "RoadDistrictPercentages", source_info = gis.content.analyze(item = roadDist_percentage_item.itemid))&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# In[44]:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;rsa_fl.append(item_id = rsa_percentage_item.itemid, upload_format = "csv", source_table_name = "RoadServiceAreaPercentages", source_info = gis.content.analyze(item = rsa_percentage_item.itemid))&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# In[45]:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;csv_items = [&lt;BR /&gt;zone_percentages_item&lt;BR /&gt;, fsa_percentages_item&lt;BR /&gt;, sra_percentages_item&lt;BR /&gt;, floodZone_percentages_item&lt;BR /&gt;, compPlan_percentage_item&lt;BR /&gt;, planDist_percentage_item&lt;BR /&gt;, urbanBound_percentage_item&lt;BR /&gt;, roadDist_percentage_item&lt;BR /&gt;, rsa_percentage_item&lt;BR /&gt;]&lt;/P&gt;&lt;P&gt;for i in csv_items:&lt;BR /&gt;print(i)&lt;BR /&gt;try:&lt;BR /&gt;i.delete()&lt;BR /&gt;except Exception as e:&lt;BR /&gt;print(e)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# In[46]:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;delete()&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# In[ ]:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Mar 2024 00:37:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/notebook-failing-randomly-or-not/m-p/1392973#M10611</guid>
      <dc:creator>RogerAsbury</dc:creator>
      <dc:date>2024-03-08T00:37:15Z</dc:date>
    </item>
  </channel>
</rss>

