imageserver exportImage versus MakeImageServerLayer python

05-29-2020 11:34 AM
New Contributor II

I'm using python and trying to download and create a layer using the exportImage functionality here:3DEPElevation (ImageServer) .  I find that I'm able to download a clipped raster from exportImage much faster than using MakeImageServerLayer_management. ExportImage takes less than 15 seconds, where MakeImageServerLayer takes 45+ seconds.  So long story short I'd like to use exportImage if possible. 

However, sometimes it works great, but sometimes intermittently, I'm receiving a 400 status code when I try to download the image using exportImage.  The request to exportImage returns an href link in the json response, but when I try to download and write it to file, the request fails with a 400. When I use retries, the file will sometimes download on subsequent attempts, but sometimes it will never download.  Even when I copy the link into a browser. 

Can anyone offer an explanation, insight, and/or solution?

My requests config is something like this:

import requests, arcpy, datetime
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry

retry_strategy = Retry(
    status_forcelist=[400, 429, 500, 502, 503, 504],
    method_whitelist=["HEAD", "GET", "OPTIONS"],
adapter = HTTPAdapter(max_retries=retry_strategy)
http = requests.Session()
http.mount("https://", adapter)
http.mount("http://", adapter)

And my imageServer code is something like this:

exportURL = r""




exportParams = {'bbox':featExtentJSON,
                'mosaicRule':{"mosaicMethod" : "esriMosaicLockRaster","lockRasterIds" : 4968},

def createExport(url, exParams):
    exportResponse = http.get(url, params=exParams)
    if exportResponse.status_code==200:
    return fileURL

def downloadImage():
    fileURL = createExport(exportURL, exportParams)
    if fileURL.find('/'):
        fileName=fileURL.rsplit('/', 1)[1]       
        r = http.get(fileURL, allow_redirects=False)
        if r.status_code==200:
            with open(tempDir+'\\'+fileName,'wb') as f:
    return fileName


0 Kudos
0 Replies