I would like to pull data from an ArcGIS Map Service, using Python (ArcPy/ArcGIS Pro), but I'm having trouble getting a token.
My guidance: https://pro.arcgis.com/en/pro-app/latest/arcpy/functions/getsignintoken.htm
This is my code:
import requests
import arcpy
url = "https://...../arcgis/rest/services/..../MapServer/5"
head = {"Accept": "application/json"}
myFilter = "/query?where=1%3D1&&returnCountOnly=true&f=pjson"
token = arcpy.GetSigninToken()
if token is not None:
try:
theToken = token['token']
theServiceUrl = url + myFilter + "&token=" + theToken
response = requests.post(theServiceUrl, headers=head)
print (response.text)
except:
print ("failed")
exit()
Produces this:
{
"error": {
"code": 498,
"message": "Invalid Token",
"details": []
}
}
So the system gave me the token to use, but says it's invalid. What am I doing wrong?