Get the token using ArcGIS Python API

15002
15
Jump to solution
03-13-2018 10:59 PM
simoxu
by MVP Regular Contributor
MVP Regular Contributor

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

Tags (2)
0 Kudos
15 Replies
DCWORK_GIS
New Contributor III

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.

0 Kudos
sredar
by
New Contributor II

What the heck, now I am getting the same thing you are with 

token = gis._con.token
 
Its returns None and just yesterday it worked
 
In a Notebook it does works but it no longer  my in local IDE. 
DCWORK_GIS
New Contributor III

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.

0 Kudos
sredar
by
New Contributor II

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

 

 

vpelleritoCritigen
New Contributor II

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.

JosephRhodes2
Occasional Contributor II

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. 

0 Kudos