How to send a synchronous query request to a Map Service using python?

557
2
11-29-2017 09:38 AM
KaraManseau
New Contributor

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()

0 Kudos
2 Replies
JonathanQuinn
Esri Notable Contributor

Sup Kara

The response from the query should only be returned when it's done.  There's a default set of 1000 or 2000 records returned on a query, so you may not get all records if there are more than 1000 features in the layer.  Is the service you're querying against public?

KaraManseau
New Contributor

Quinnnnnnnn!

Thanks for the response - I actually just tried again this morning and it seems to be working just fine. Not totally sure what was going on yesterday, could have been an issue with my own network. 

0 Kudos