Esri / ArcREST

python package for REST API (AGS, AGOL, webmap JSON, etc..)
Apache License 2.0
192 stars 155 forks source link

Calls to content.UserContent.exportItem always return 400 on long-running jobs #86

Closed chadcooper closed 9 years ago

chadcooper commented 9 years ago

Following this sample, if I attempt to export a feature service to FGDB from AGOL that results in a large (900+ MB) FGDB, exportItem always fails with a 400 - Error updating file item. BUT, the FGDB gets created just fine and I can manually download it from My Content on AGOL.

If I run same code on really small feature service, all works well and the job completes just fine.

As a hack I tried putting a time.sleep(300) in before calling exportItem.itemData(), but that isn't working in my client environment and now itemDataPath is returning False.

agolSH = AGOLTokenSecurityHandler(username=username,
                                  password=password)

portalAdmin = arcrest.manageorg.Administration(securityHandler=agolSH)
content = portalAdmin.content

item = content.item(itemId)

uc = content.usercontent(username=item.owner)
res = uc.exportItem(title=zip_name,
                    itemId=itemId,
                    exportFormat="File Geodatabase"
exportItemId = res['exportItemId']
jobId = res['jobId']
exportItem = content.item(exportItemId)
serviceItemId = res['serviceItemId']
status = uc.status(itemId=exportItemId, jobId=jobId, jobType="export")
while status['status'].lower() != 'completed':
    status = uc.status(itemId=exportItemId, jobId=jobId, jobType="export")
    if status['status'].lower() == 'failed':
        utils.make_message("ERROR: Export failed.")
        break
del status

itemDataPath = exportItem.itemData(f=None, savePath=savePath)
uc.deleteItem(item_id=exportItemId)
achapkowski commented 9 years ago

i will take a look. thank you.

achapkowski commented 9 years ago

Set wait=True.

Try this:

        import arcrest
        username = ""
        password = ""
        itemId = ""
        zip_name = ""
        savePath = r""
        agolSH = arcrest.AGOLTokenSecurityHandler(username=username,
                                          password=password)
        portalAdmin = arcrest.manageorg.Administration(securityHandler=agolSH)
        content = portalAdmin.content
        item = content.getItem(itemId)
        user = content.users.user(username=item.owner)
        res = user.exportItem(title=zip_name,
                              itemId=itemId,
                              exportFormat="File Geodatabase",
                              wait=True)
        exportItemId = res.id
        exportItem = content.getItem(exportItemId)
        itemDataPath = exportItem.itemData(f=None, savePath=savePath)
        exportItem.userItem.deleteItem()
chadcooper commented 9 years ago

Regarding using wait=True: looks like that is v3 item, I'm using v2 right now. Can you explain what wait=True does exactly?

Regarding the issue I'm having with deploying this: I can actually get this to work fine in my local dev env, but when trying to deploy to my client's env (with very high security), it is bombing, but only on large downloads. A colleauge suggested it could be the firewall filtering content based on size, since I can pull down a zip created by this process that is say 125MB, but not one that is almost 1GB in size. Will update here on what I find. Thanks.

MikeMillerGIS commented 9 years ago

ExportItem is a async gp task, setting wait to true just loops until the process finishes or fails.

chadcooper commented 9 years ago

Hmm, thanks, Mike. So exportItem really only handles the export of the AGOL item (a feature service in my case) out to a export format (FGDB in my case), correct? If so, that part is working fine, even though it returns a result of failed on the larger items. I'm really starting to think my real problem is on my client's env with some sort of security setting that is prohibiting my process from downloading the nearly 1GB zipped up FGDB.

MikeMillerGIS commented 9 years ago

Export Item - http://resources.arcgis.com/en/help/arcgis-rest-api/index.html#//02r30000008s000000

This returns a job id, that job is run in the portal/online. You have to monitor that job for a status update. That is what the Wait parameter does in ArcRest. When the job is done, a new item is created, which you can download.

achapkowski commented 9 years ago

@chadcooper, @MikeMillerGIS When wait is set to false, the job id is not returning, I corrected for this issue. This means if you specify wait=False and want to check status yourself, you now can.
If wait is set to True, then the function will return the useritem object as expected.

See the doctstring for the complete changes in the function.

Andrew