I have this code snip below.
- Trying to get a token
- return that token
- and use gis.content.get(feature_layer_id) to secure access to a service
- Line 14 The variable "custom_token" prints with no issues
- Line 18 prints fine as well "Token successfully generated! Expires at timestamp: 1780364453189"
- Line 21 prints back NONE
- and Line 23 gives error: Exception: You do not have permissions to access this resource or perform this operation.
(Error Code: 403)
The user Name and password are owner level permissions and have access to everything in our Enterprise... so im confused.
AND confused why line 21 returns NONE
The reson I am going this route is I need to increase the token expiration time... not sure how to do it any other way...
otherwise I would just do this
if portal_username == '' and portal_password == '':
gis = GIS(profile='Survey123_prof')
else:
gis = GIS(portal_url, portal_username, portal_password)
token = gis._con.token
item_object = gis.content.get(feature_layer_id)
ANY thoughts?
token_url = f"{portal_url}/sharing/rest/generateToken"
payload = {
"username": portal_username,
"password": portal_password,
"client": "referer",
"referer": portal_url,
"expiration": expiration_minutes,
"f": "json"
}
response = requests.post(token_url, data=payload)
token_data = response.json()
custom_token = token_data["token"]
print("custom token " + custom_token)
gis = GIS(url=portal_url, credentials={"token": custom_token})
print(f"Token successfully generated! Expires at timestamp: {token_data['expires']}")
tokenvalue = gis._con.token
print(tokenvalue)
item_object = gis.content.get(feature_layer_id)
print(item_object)