I'm trying to write the returned JSON from the Map Service query request to file, but if the server is too slow or there is too much data, it appears to be returning results incrementally causing the script to fail. I am wondering if there is way to force the results to fully load before the script continues on, but am having troubles finding a solution. Here is my script thus far:
params = {
'where': '1=1',
'geometryType': 'esriGeometryEnvelope',
'spatialRel': 'esriSpatialRelIntersects',
'outFields': '*',
'returnGeometry': 'true',
'returnTrueCurves': 'false',
'returnIdsOnly': 'false',
'returnCountOnly': 'false',
'returnZ': 'false',
'returnM': 'false',
'returnDistinctValues': 'false',
'f': 'pjson'
}
url = server + "/" + str(i) + "/query"
r = requests.post(url, params)
result = json.load(urllib.urlopen(url))
jsonFile = open(name, 'w')
json.dump(result, jsonFile)
jsonFile.close()