Deleting ArcGIS Online item - does not exist or is inaccessible

831
2
05-21-2019 01:05 PM
WightmanAdmin
New Contributor III

I use a Python script to export an item to a FGDB, download said FGDB and then delete it. The script successfully deletes the FGDB, but when I go to the AGOL account, it is still there, and I am unable to remove it. When I try to delete the item I get:

And when I try to view the item in AGOL, I get:

Below is my script (some of which I got from another user on this forum, but I can't find the thread):

from arcgis.gis import GIS
from datetime import datetime
from pathlib import Path
from zipfile import ZipFile
import time, os, zipfile

print('Initializing...\n')
gis = GIS(site,user,pw)
print('Logged on...\n')

fs = gis.content.get('XXXXXXXXXXXXXXXXXXXXXXX')
print(f'Exporting Feature Service to FGDB - {fs.name}')
fs.export(fs.name+'_temp','File Geodatabase',parameters=None,wait='True')

# search for fgdb and get item id
while True:
    try:
        print('Locating FGDB')
        search_fgb = gis.content.search(query=fs.name+'_temp')
        print(search_fgb)
        fgb_item_id = search_fgb[0].id
        fgdb = gis.content.get(fgb_item_id)
        break
    except IndexError as e:
        print(e)
        print('FGDB does not exist yet')

data_path = Path('./monthlyDownload')

if not data_path.exists():
    data_path.mkdir()

print('Downloading FGDB')
fgdb.download(save_path=data_path)

'''while statement runs until a valid zipped file is created'''
## randomly the output is a 1 KB file that is not a valid zipped file.
## The while statement forces a valid zipped file to be created.
print('Finalizing zip file')
zipfullpath=os.path.join(data_path,fs.name+"_temp.zip")#full path to the zipped file once it is downloaded to your computer
while zipfile.is_zipfile(zipfullpath)==False:
    fgdb.download(save_path=data_path)

# delete temp FGDB in AGOL
print('Deleting temporary FGDB')
while True:
    try:
        fgdb.delete()
    except RuntimeError:
        break

0 Kudos
2 Replies
DouglasCochran
Occasional Contributor II

Hi,

Have you tried clearing your cache or running your browser in incognito mode to see if its a cache issue? Also please try re-signing in to your ArcGIS Online organization account. Hope that works!

0 Kudos
WightmanAdmin
New Contributor III

This sadly didn't work. I cleared the cache, logged in and out, and tried the same in incognito mode. Maybe I'm calling the fgdb.delete(function too soon. Perhaps if I created a list of FGDBs deleted, and then called a function to delete all those FGDBs that would work. Just spit-balling. 

0 Kudos