I am attempting to generate a token from REST using Python for portal admin but only receiving the generateToken page in HTML as a response. We are running Enterprise version 10.8.1. This is my code:
# A function to generate a token given username, password and the adminURL.
def getToken(username, password, baseURL):
# Token URL is typically http://server[:port]/arcgis/admin/generateToken
tokenURL = "{}arcgis/sharing/rest/generateToken".format(baseURL)
params = urllib.parse.urlencode({'username' : username,
'password' : password,
'client' : 'referer',
'referer': baseURL,
'expiration': 60,
'f' : 'json'})
headers = {"Content-Type": "application/x-www-form-urlencoded", "Accept": "text/plain"}
# Read response
response = requests.post(tokenURL, data=params, headers=headers)
return response.text
I have used similar syntax before to generate a token with ArcGIS Server admin version 10.8.1, and that code still works. Any reason why the Portal generateToken would be more finicky, or what the problem might be here? It seems like something with the request must be off to not return the token in response.