I am trying to use this example and it does not work...
https://pro.arcgis.com/en/pro-app/latest/arcpy/functions/signintoportal.htm
The last line Fails : The example dosent have the appropriate number of arguments... If I remove one of them it then asks for the Password...
resp = arcpy.SignInToPortal(portal_url, token=token, token_referer=portal_url, token_expiry=token_expiry)
File "C:\Program Files\ArcGIS\Pro\Resources\ArcPy\arcpy\__init__.py", line 2494, in SignInToPortal
return _SignInToPortal(*args, **kwargs)
TypeError: SignInToPortal() takes at most 3 arguments (4 given)
>>>
Yet the documentation shows many more arguments
SignInToPortal (portal_url, {username}, {password}, {cert_file}, {key_file}, {token}, {token_referer}, {token_expiry})
It appears ESRI documentation is wrong ... whats the correct way to use a TOKEN instead of username and password
import arcpy
import requests
# assemble arguments into a dictionary
# for additional help on the generateToken REST service, see your portal documentation
portal_url = "https://example.com/portal/"
gen_token_url = f"{portal_url}sharing/rest/generateToken"
params = {"f": "json", # Response format
"username": "username", # Your ArcGIS Portal username
"password": "password", # Your ArcGIS Portal password
"referer": gen_token_url, # URL of the referring application (usually your portal)
"expiration": 60 # Token expiration time in minutes (default: 60)
}
# get a token using python's requests module
resp = requests.post(gen_token_url, data=params)
# check response. If failed, show response.text
assert resp.status_code == 200, resp.text
# now use token with SignInToPortal
token = resp.json()['token']
token_expiry = int(resp.json()['expires']/1000) # convert to seconds since generateToken returns milliseconds
resp = arcpy.SignInToPortal(portal_url, token=token, token_referer=portal_url, token_expiry=token_expiry)
THe
Solved! Go to Solution.
Ok then that's a 2.9 ArcGIS Pro install. Your arcpy version would be 2.9, the 3.7.11 refers to the Python version.
2.9 ArcGIS Pro archived help shows only the 3 arguments available unfortunately https://pro.arcgis.com/en/pro-app/2.9/arcpy/functions/signintoportal.htm
I think this method only had 3 arguments before 3.x of ArcGIS Pro. If you're on 2.x Pro that would make sense.
Im running it with arcpy 3.7.11
Ok then that's a 2.9 ArcGIS Pro install. Your arcpy version would be 2.9, the 3.7.11 refers to the Python version.
2.9 ArcGIS Pro archived help shows only the 3 arguments available unfortunately https://pro.arcgis.com/en/pro-app/2.9/arcpy/functions/signintoportal.htm