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.
import os
import arcpy
from datetime import datetime
n = datetime.now()
datestamp = n.strftime("%B_%d_%Y")
mxd = arcpy.mapping.MapDocument(r"D:\temp\AGOL_Data.mxd")
df = arcpy.mapping.ListDataFrames(mxd)[0]
destPath = r"D:\temp"
outgdb = destPath + "\\GarbageCanSDE.gdb"
for lyr in arcpy.mapping.ListLayers(mxd, '', df):
if lyr.isFeatureLayer == True:
d = lyr.name.encode('ascii', 'ignore')
d = d.replace(' ','_')
#file_name = d + "_" + datestamp + ".shp"
file_name = outgdb + "\\" + d + "_" + datestamp
dest1 = os.path.join(destPath, file_name)
print(file_name)
print(type(file_name))
print(dest1)
if arcpy.Exists(dest1):
arcpy.Delete_management(dest1)
print("deleted")
try:
arcpy.CopyFeatures_management(lyr, dest1)
except:
pass
Hi Darryl,
In that piece of code there is no reference to the ArcGIS Python API...
Best regards,
Xabier
Has anyone tried using the Windows Task Scheduler to run this script when not logged in to their computer?
I have an issue were the Task Scheduler will start the script, creates the temporary file geodatabase in AGO and then stops? To set up the task, I followed: Schedule a Python script or model to run at a prescribed time: 2019 update stored my credentials, and ran with highest privileges. I've also checked the box to "Allow others to export to different formats" on the hosted feature service. For reference, the Windows Task Scheduler runs the script perfectly if I am logged in to the computer. Any thoughts?? Tom Laue Xabier Velasco Echeverría
We will be trying to do so with FME software.
This is a great script and I have gotten the .zip file to download. However, the script seems to be getting stuck and never gets passed "Zipping exported geodatabase for download...", When I finally stop the script, the .zip file is there with all of the expected data, but not sure why I can't get the script to complete. Can you offer any insight?
This has been giving me grief. as far as I can tell its trying to reference an undeclared variable?
While borrowing from many of these comments and script ideas you all have posted, I have an error in python right after the download from AGOL to the local zip file. Where it seems the test for valid zip is not done fast enough to prevent one extra loop from trying the download, or it is some kind of timeout as this runs for an hour.
This is the part that finishes creating the correct zip file download but errors off right at the end in the ArcGIS Pro connection.py and request.py.
I believe that I can put in a try catch and work around this, but would prefer to understand the issue and have it work with out that tactic.
I did change the code to load the bool check of is a proper zip file and it ran through with the result finishing and creating the valid zip file of the download but with an error still
Reason for exception 'bool' object does not support item assignment
I took this to mean it was still failing in the arcpro connection.py on line 816 trying to check for a Boolean json.
I have not tried this yet but possibly I am missing a parameter of 'f' and setting it to fgd ?? Hard to find the documentation on this as it relates to fgb.dowload.
As of now it just takes in the file name, but in the manual web interface you do have to choose a shapefile or fgdb or etc....
If I find an answer I will update this memo....
Removing the loop seems to solve the issue and keeps the correct data downloaded.
There is a new issue that I will enter in a new thread - The manual or via python download of AGOL Hosted feature to a fgdb changes the creator and edited by fields to be the account doing the download - I did take some input from a post regarding params for publishing that would preserver tracking data and when I try it, the export still runs but does not preserve the data.
Hi Richard, what is the size of the data you are downloading? I had tu use the loop as there were issues while downloading big geodatabases (i.e. 1.8GB) without the loop.