Hi,
I apply the following workflow to download a hosted feature service as a file geodatabase:
from arcgis.gis import GIS
gis = GIS("https://www.arcgis.com", USER, PASSWORD)
servicio = gis.content.get('XXXXXXXXXXX')
itemDescargar = servicio.export(nombre, 'File Geodatabase', parameters=None, wait='True')
fgdb = gis.content.get(itemDescargar ['exportItemId'])
fgdb.download(save_path='c:\modelbuilder')
If I execute like this, the downloaded ZIP has 1 KB. If I wait several seconds to download, the downloaded ZIP has the proper size (14MB). That means, servicio.export is still working while I try to download as I am calling from a variable.
If I instead execute servicio.export(nombre, 'File Geodatabase', parameters=None, wait='True') without a variable, the process finishes correctly before the next line of code is executed, but then I do not know what is the value of exportItemId in order to download it. How do I get the results of servicio.export? I mean, how do I get values from the output message? i.e. {'type': 'file', 'size': 61145088, 'jobId': '359e30e3-0fc7-4925-8e92-354a4ccdd478::XXXXXXXX', 'serviceItemId': 'XXXXXXXX', 'exportFormat': 'fileGeodatabase', 'exportItemId': 'XXXXXXXXX'}
Solved! Go to Solution.
I found out a workaround for this bug.
from arcgis.gis import GIS
gis = GIS("https://www.arcgis.com", USER, PASSWORD)
servicio = gis.content.get('XXXXXXXXXXX')
servicio.export(nombre, 'File Geodatabase', parameters=None, wait='True')
items = gis.content.search(nombre)
fgdb = gis.content.get(items[0].itemid)
fgdb.download(save_path=arcpy.env.scratchFolder)
The documentation for the API is a bit tricky, but if you search content you can get the item ID of the new item (FGDB). Anyway, the export function should not be asyncronous when you use the parameter wait = True. That means, if you call the export function inside a variable, why does it register as downloaded although the download is not finished yet?
For the API developers:
Summing it up, how may I access the dictionary that outputs from an item.export? You can do that with the function results in arcpy, what is the proper way to do it with the arcgis module? I guess it should be super easy, but could not find examples in the documentation
I found out a workaround for this bug.
from arcgis.gis import GIS
gis = GIS("https://www.arcgis.com", USER, PASSWORD)
servicio = gis.content.get('XXXXXXXXXXX')
servicio.export(nombre, 'File Geodatabase', parameters=None, wait='True')
items = gis.content.search(nombre)
fgdb = gis.content.get(items[0].itemid)
fgdb.download(save_path=arcpy.env.scratchFolder)
The documentation for the API is a bit tricky, but if you search content you can get the item ID of the new item (FGDB). Anyway, the export function should not be asyncronous when you use the parameter wait = True. That means, if you call the export function inside a variable, why does it register as downloaded although the download is not finished yet?
Thanks for this.
I was getting the "'dict' object has no attribute 'download'" error until I changed the wait parameter from a string:
servicio.export(nombre, 'File Geodatabase', parameters=None, wait='True')
to a boolean:
servicio.export(nombre, 'File Geodatabase', parameters=None, wait=True)
I was also intermittently getting the 1 KB zipped file export.
After a lot of testing, I found a solution that has been working for me. I used Xabier Velasco Echeverría's script (above) as a starting point and made a couple of additions:
Attached is my script.
I tested your script. Ran it in the arcgis pro version of python. And it worked first time.
Excellent documentation in the python script for novices like me!
I tried this script - but am getting an error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "c:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis.py", line 2590, in __getattr__
raise AttributeError("'%s' object has no attribute '%s'" % (type(self).__name__, name))
AttributeError: 'Item' object has no attribute 'export'
Not sure why the item doesn't have this ability? In the settings in AGOL I have this turned on
Any thoughts?
Thanks
Darryl
Hi Darryl,
What is the size of the geodatabase that you are trying to download?
I don't know the exact size since it is coming from AGOL, but it is a feature service hosted by AGOL with under 100 points, and only about 10 attributes. So quite small.
Ok, could you please post the code you are executing so that I may check what is going on?