Select to view content in your preferred language

How can I access my ArcGIS online content using the Python API?

1254
6
09-17-2018 01:57 PM
deleted-user-4LjGx0CueIPn
Deactivated User

Hello,

I been trying to access my ArcGIS online content using the API. So far I been able to access by Connecting through ArcGIS Pro but I would like to use my actual credentials to access the account. 

I looked into the following method:

print("ArcGIS Online Org account")    gis = GIS("NyCompanyURL", "MyUserName", "MyPassword")print("Logged in as " + str(gis.properties.user.username))

when I use this method, the scripts seems to be running but nothing happens. I am assuming I am using the wrong approach for an ArcGIS enterprise account. Any help is appreciated. 

Tags (2)
6 Replies
JoshuaBixby
MVP Esteemed Contributor

Your few lines of code work fine for me, and I tested with 2 different accounts.  What if you try your code in an interactive Python session in a Command Prompt? 

0 Kudos
deleted-user-4LjGx0CueIPn
Deactivated User

Joshua,

thank you for testing the code. IF I try the same code I get an error message about "Unable to generate token". 

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

If I had to guess, your credentials are not working.  Make sure to use Python raw strings (r"username") in case your username or password has any special characters that Python might be misinterpreting.

0 Kudos
deleted-user-4LjGx0CueIPn
Deactivated User

Joshua,

that is what I was thinking. I'm starting to think it has to do with my credentials. My password does have special characters because it is work policy. I will try the next suggestion see if that goes through. Thanks a lot. 

0 Kudos
MichaelSchoelen
Frequent Contributor

What are you using for your company URL? For that GIS definition to work I had to do one of the following:

  1. For whatever reason, I needed ArcGIS Pro to successfully log in before running the API. Pop it open and sign in. Then reattempt.
  2. Format the portal URL as 'org.maps.arcgis.com' , with nothing else in the URL (i.e. /home)
  3. Just leave that portal URL parameter blank, and it will default to the AGOL org that it is associated with
0 Kudos
deleted-user-4LjGx0CueIPn
Deactivated User

Michael,

I am using my enterprise company home page (https://CompanyName.maps.arcgis.com). I am using ArcGIS Pro to log in. That approach looks similar to your #1 approach. I will try # 3 see if that gives any results. Thank you  

0 Kudos