Last active
April 22, 2022 18:15
-
-
Save jgravois/d4a49a7ba38d49d3c42a21706cf69d79 to your computer and use it in GitHub Desktop.
what's required to use python requests to POST to AGOL/ArcGIS Server?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import json | |
agol_url = r'http://services1.arcgis.com/uRIm5IkWjDXybgFb/arcgis/rest/services/LA_Nhood_Change/FeatureServer/0/query' | |
server_url = r'http://sampleserver6.arcgisonline.com/arcgis/rest/services/EmergencyFacilities/FeatureServer/0/query' | |
# i tried several different headers, to no avail | |
# headers={"Content-type": "application/x-www-form-urlencoded","Accept": "text/plain"} | |
# headers = {"Content-Type": "application/x-www-form-urlencoded", "Accept":"/*/", "Accept-Encoding":"gzip, deflate", "Accept-Language":"en-US,en;q=0.8,ar;q=0.6"} | |
headers={"content-type":"application/json","Accept":"application/json"} | |
rGet = requests.get(agol_url, {"f":"json","where":"1=1","returnCountOnly":"true"}, headers=headers) | |
print 'python get request returns JSON, as expected' | |
print rGet.text | |
rPost = requests.post(agol_url, data=json.dumps({"f":"json","where":"1=1","returnCountOnly":"true"}), headers=headers) | |
print 'python post request returns html, indicating that parameters are ignored' | |
print rPost.text | |
# shoot, i cant even figure out how to POST with cURL | |
# curl --data "f=json&where=1=1&returnCountOnly=true" http://services1.arcgis.com/uRIm5IkWjDXybgFb/arcgis/rest/services/LA_Nhood_Change/FeatureServer/0/query | |
# curl -H "Content-Type: application/json; charset=UTF-8" -X POST -d '{\"f\":\"json\"}' http://services1.arcgis.com/uRIm5IkWjDXybgFb/arcgis/rest/services/LA_Nhood_Change/FeatureServer/0/query |
Thanks for posting this John, ArcGIS is awesome but their API can be a nightmare sometimes.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
two years later, I finally figured it out: https://stackoverflow.com/a/56552964/3019940