How to Use Python to Log into AGOL

3116
11
08-25-2020 10:58 AM
AmberTobin
New Contributor III

We have an AGOL Organization account. Every day I run python code in the IDLE (2.7.16) window that automates stuff in ArcMap and uploads it to AGOL. The only problem is that I have to manually go into ArcMap to sign into AGOL. Is there code I can add to my script that will log me in? I've looked into the ArcGIS API for Python and its all a little over my head. I can't get the GIS module to import into IDLE (2.7.16). 

0 Kudos
11 Replies
JoeBorgione
MVP Emeritus

Amber - Python 2.x is old and in the way.  Yes there are some notable differences, and yes some of your scripting will need to be edited. If you have millions of lines of code, the transformation will be painful.  Even the versions of Python 3.x that ship with ArcGIS Pro are not current (see Timeline for python upgrade? ).  So what to do?

Personally, I only use the IDLE (Integrated Development and Learning Environment) for quick and dirty python scripts, and that's very rare. I prefer a more robust IDE for the heavy lifting and just general script creation.  Since you have ArcGIS Pro installed, the default environment will have python 3.x installed.  It sounds like you have ArcMap installed as well so in your C drive you have an install directory called Python 2.'something'. (I don't have ArcMap installed anymore).  Try this: right click on an existing python script and see if you get the choice to EDIT with IDLE(ArcGISPro).  If so, you'll be in the Python 3.x environment and you should be good to go....

edited to add:  How sunsetting Python 2 affects ArcGIS 

That should just about do it....
0 Kudos
AmberTobin
New Contributor III

Thanks Joe! To be honest with you, my code was made sort of quick and dirty. I used model builder as a base (exported to python) and then modified and added more code in python using the arcpy modules as necessary. I wrote the code a few years ago. I do have a lot code and 4 scripts to run. Most recently I created a script that runs all 4 of my scripts instead of having to run each of them individually. 

My main goal is to have the script run when I'm not in the office. Instead of trying to combine the log-in process with my outdated IDLE 2.7 code I could write a second one in a more current platform. I was thinking of setting up a windows scheduler, I would just set-up 2: one to log-in to AGOL and one to run my code that updates the feature service. 

I've used ArcMap for so long that I've been too stubborn to switch over to Pro, GIS is a small part of my job function so I need to be proficient in other non-GIS software as well. 

In terms of deprecation, from how I comprehend it, the ArcGIS python libraries were downloaded when I downloaded ArcMap. Even if ESRI no longer supports certain libraries, they exist on my C drive so they should run forever as long as I don't delete them and work with an ArcMap version that supports it (for the code that does the ArcMap stuff).  I could be totally wrong here.

Ah ha! I don't know why I've never noticed this but I do see the option to EDIT with IDLE(ArcGISPro)! I'll have to try that out!

Thanks!

0 Kudos