In Getting correct sign-in token for ArcGIS REST Service using ArcPy with ArcGIS Pro I found that I was trying to use a token received from one source, on a different server, which didn't work.
Now I'm sure I'm staying with the same service, but I'm caught in a loop.
My "ArcGIS REST Services Directory" is located at https://<server>.<domain>/arcgis/rest/services
and looks like this in a web browser:
Home > services Help | API Reference
JSON | SOAP
Folder: /
Current Version: 10.71
...
So, now I try and acquire a token:
# create a session object
s = requests.Session()
# set username and password
s.auth = (username, password)
url = 'https://<server>.<domain>/arcgis/tokens/generateToken'
response = s.post(url)
print ('RESPONSE: ' , end = '')
print (response)
print ("\n")
print (response.text)
and get this:
URL: https://<server>.<domain>/arcgis/tokens/generateToken
RESPONSE: <Response [200]>
Invalid request <br>Usage: https://<server>.<domain>/arcgis/tokens?request=gettoken&username=username&password=password&<br>Usage: https://<server>.<domain>/arcgis/tokens/generateToken?username=username&password=password&<br>Usage: https://<server>.<domain>/arcgis/tokens/gettoken.html<br>
As I understand it, I must supply credentials to acquire the token, which makes sense. So I use the instruction given in the failed response, and supply this:
URL: https://<server>.<domain>/arcgis/tokens/generateToken?username=_________&password=________
RESPONSE: <Response [405]>
which gets this:
Generate Token request should not contain username and password in the query string.