Hello folks,
Can anyone give me a clue how to access token using ArcGIS Python API?
I believe a token was generated when instantiating the GIS class as follows:
from arcgis.gis import GIS
gis=GIS(url="https://...",username="",password="")
I thought the token should be stored somewhere in the gis object, I looked up and down the list of properties and methods but nowhere can I find it.
Any advices and suggestions are highly appreciated.
Thanks
Simo
Solved! Go to Solution.
That does work, but in my case, my goal is to use this script, and others like it in AGOL Notebooks, and my org doesn't pay for ArcPy there. So I'm limited to only using the API for Python.
What the heck, now I am getting the same thing you are with
But yesterday it did? That's really weird. I noticed it after we upgraded from 2.7 to 3.2, but maybe it's something else. ESRI's been non-responsive about the issue. Maybe it's a bug.
The issue appears to be related to how you access the 'gis', this works:
gis = arcgis.GIS(url='https://{org}.maps.arcgis.com/', username=user, password=pswrd)
token = gis._con.token
this does not:
gis = arcgis.GIS("pro")
token = gis._con.token
This is bad... Now, even though the user is logged into the Portal in Pro, you must pass those same credentials hardcoded in your Python script.
Thanks, @sredar for discovering this.
Same issue here. @sredar's workaround is great for my current project (thanks), but there are lots of other cases where arcpy isn't available and I need to get an access token from the GIS object.
This is another option for getting the token without needing to store the credentials in the script, but it does require some initial setup on the computer that you plan to run the process on because you need to create a profile that will be used for all your future scripts.
1st Run: