Get the token using ArcGIS Python API

6456
7
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
1 Solution

Accepted Solutions
JakeSkinner
Esri Esteemed Contributor

Hi Simo,

Yes you can find this with the following:

import arcgis
from arcgis.gis import GIS
gis = GIS("https://www.arcgis.com", "jskinner_CountySandbox", "*****")
token = gis._con.token
print(token)

View solution in original post

7 Replies
JakeSkinner
Esri Esteemed Contributor

Hi Simo,

Yes you can find this with the following:

import arcgis
from arcgis.gis import GIS
gis = GIS("https://www.arcgis.com", "jskinner_CountySandbox", "*****")
token = gis._con.token
print(token)
simoxu
by MVP Regular Contributor
MVP Regular Contributor

Hi Jake,

That works! Thanks a lot.

Simo

0 Kudos
RohitSingh2
Esri Contributor

Hi Simo,

Would you mind sharing why you need access to the token though? Is there something in the API or your workflow that needs access to this token?

Thanks,

Rohit

0 Kudos
simoxu
by MVP Regular Contributor
MVP Regular Contributor

Hi Rohit,

I am migrating some code built roughly 3 years ago using ArcREST. In one piece of the code, I need to download the data in the feature service(create Replica) and save the data in a local database. 

As you know, the replica will be stored in AGO organization as the following:

http://services1.arcgis.com/pdfadfdafkkllADFAA/ArcGIS/rest/services/RIASP22015/FeatureServer/replica...

To download the zip file and unzip it, I need a token to access AGO organization. This was required in my old code, and I am doing a like for like migration at the moment.

Hope this explains it. 

Cheers,

Simo

JakeSkinner
Esri Esteemed Contributor

Hi Simo,

Just an FYI, you can use the following tool to download your data:

https://community.esri.com/docs/DOC-6496-download-arcgis-online-feature-service-or-arcgis-server-fea... 

simoxu
by MVP Regular Contributor
MVP Regular Contributor

Thank you Jake.

0 Kudos
AllisonMuise2
New Contributor III

@RohitSingh2 are there any plans to add the ability to access & download replicas directly through the Python API? I am running into this same issue as @simoxu . The Python API can get us so close, but then to need to use requests to get the path to the output is a bit disappointing. The API has spoiled us by making most of these actions so easy!