Select to view content in your preferred language

Backup: Export hosted feature to FGDB

300
4
05-31-2024 01:29 PM
SanchezNuñez
Occasional Contributor II

Good afternoon,

 

I am trying to create a backup script to copy several hosted feature classes. I am testing the scrip in the Notebook. Any idea why this line fails?

### Create Backup
dataitem.export(title=tempfile,export_format="File Geodatabase",parameters=None,wait=True)

 

--------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
In  [32]:
Line 2:     dataitem.export(title=tempfile,export_format="File Geodatabase",parameters=None,wait=True)

File C:\Users\e160795\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone\lib\site-packages\arcgis\gis\__init__.py, in export:
Line 12859: export_item = Item(gis=self._gis, itemid=res["exportItemId"])

KeyError: 'exportItemId'
---------------------------------------------------------------------------

In [ ]:
 
 
 
 
 
0 Kudos
4 Replies
Brian_Wilson
Regular Contributor II

Can you give us the code you used above the line generating the error?

0 Kudos
SanchezNuñez
Occasional Contributor II

Godo morning @Brian_Wilson 

Sure, here is the code:

###Authenticate to ArcGIS Online
gis=GIS("Pro")

output=r"C:/Workspace/Backups"

currentItemID = "0cf4485596424ad3a736420ed9a2d727"
dataitem=gis.content.get(currentItemID)
dataitem

### Create Backup
tempfile=strftime(dataitem.title+"_backup_%Y%m%d")
tempfile

### Create Backup
dataitem.export(title=tempfile,export_format="File Geodatabase",parameters=None,wait=True)

 

And the error message:

---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
In [32]:
Line 2: dataitem.export(title=tempfile,export_format="File Geodatabase",parameters=None,wait=True)

File C:\Users\e160795\AppData\Local\ESRI\conda\envs\arcgispro-py3-clone\lib\site-packages\arcgis\gis\__init__.py, in export:
Line 12859: export_item = Item(gis=self._gis, itemid=res["exportItemId"])

KeyError: 'exportItemId'
---------------------------------------------------------------------------

 

0 Kudos
SanchezNuñez
Occasional Contributor II

I just selected another hosted feature and it exports and downloads the feature. But when I download the file it does not have any format.

 

 

#Set the download path for the ZIP files
output=r"C:/Workspace/Backups"
data_path = Path(output)
data_item.download(output)
print("Exported item: {}".format(data_item))
print("Downloaded "+str(data_item.title)+" to "+output)

0 Kudos
JoseSanchez
Regular Contributor

Finally, I was able to export my hosted feature. in the setting tab, I had to allow to export the feature.

 

from time import strftime
from arcgis.gis import GIS
gis = GIS("Pro")
public_data_item_id = '0cf4485596424ad3a736420ed9a2d727'
servicio = gis.content.get(public_data_item_id)
itemName = gis.content.get(public_data_item_id).title
t = time.localtime()
timestamp = time.strftime('%Y%m%d',t)
nombre = "{}_Download{}".format(itemName, timestamp)
servicio.export(nombre, 'File Geodatabase', parameters=None, wait=True)
items = gis.content.search(nombre)
fgdb = gis.content.get(items[0].itemid)
output=r"C:/Workspace/Backups"
fgdb.download(save_path=output)

 

 

0 Kudos