automatic logon to the gis()

793
3
09-14-2020 12:23 AM
IanHamilton2
New Contributor III

HI, I am looking for the best practice way to make my script run in ArcGIS Pro and Exterprise portal without modification - specifically getting the gis().

The user will be already logged in and have an active portal before running the script.

At the moment I use gis("home") when using portal and gis("Pro") when using Arc Pro

is there a test I can use to determine whether the script is running in in Pro or Portal so I can choose?

Alternatively, is there a different approach I should be using?

Thanks,

Ian

0 Kudos
3 Replies
MehdiPira1
Esri Contributor

 Ian Hamilton

You can rename your scripts.

e.g. pro_script.py

       portal_script.py

0 Kudos
JoshuaSharp-Heward
Occasional Contributor III

Hi,

I think this could work by putting the two login methods in a try-except statement.

Something like this:

try:
    # first attempt to login using notebook specific home
    gis = GIS("home")
except:
    # otherwise login using active portal in pro
    gis = GIS("pro")

I'm pretty sure running GIS("home") outside of ArcGIS Notebooks will throw up an error, allowing this switch to work.

IanHamilton2
New Contributor III

Thanks, I'll give this a go

0 Kudos