Request data from ArcGIS Server through python

921
1
09-08-2017 12:45 PM
deleted-user-9zlChDJzM-SF
New Contributor III

I am having an issue when trying to create a script that will return a list of values from an ArcGIS Server service from a json query in python. I have the following code below which I thought would do the trick but it returns the HTML and not the json results as I was hoping. Could someone please help to let me know what I'm doing wrong?

import requests, json

inFeatures = "http://wildfire.cr.usgs.gov/arcgis/rest/services/geomac_dyn/MapServer/0/query"
json_payload = { 'where': 'acres > 5','f': 'json', 'outFields': 'latitude,longitude,incidentname,acres'}
r = requests.get(inFeatures, params=json_payload)
print r.text
0 Kudos
1 Reply
JonathanQuinn
Esri Frequent Contributor

If you make that request manually in your browser, some sort of token is attached to the request:

https://wildfire.cr.usgs.gov/arcgis/rest/services/geomac_dyn/MapServer/0/query?where=acres+%3E+5&tex... 

Since you're not submitting the request with that token, it redirects you to an HTML page.