Check to see what user (or if no user) is logged into Pro

127
2
a week ago
TL2
by
Occasional Contributor III
try:
    gis = GIS("Pro")


except:
     logger.error()

 

I would like to get notified (except) when Pro fails to log in because no user is currently logged in or return the user that is logged in.  

Tags (3)
0 Kudos
2 Replies
DavidSolari
Occasional Contributor III
if not arcpy.GetSigninToken():
    fail()
portal = arcgis.GIS("Pro")
0 Kudos
EdMorris
Esri Contributor

Hi

I'm not sure if you found a solution to your original post? If not then you you might find the following code snippet useful:

 

from arcgis.gis import GIS
try:
    myGIS = GIS(url = 'pro')
    print(myGIS.users.me)   # This will display the
                            # user who accessed ArcGIS Pro and is used to
                            # then authenticate the connection to your portal

except ValueError as e:     # if nobody has authenticated using ArcGIS
                            # Pro then a ValueError is generated.....
    print("There was an error\n")
    print(f"The error is:\n\t{e}")

 

Hopefully this will do the trick and identify who has authenticated using ArcGIS Pro and a suitable error message displayed if nobody has authenticated.

If you have already authenticated using ArcGIS Pro; then run the above code and THEN sign out of ArcGIS Pro and re-run the code again, then the myGIS.users.me returns a None object. You might want to code for that outcome...?

I hope this helps you out - Let me know how you get on?

many thanks

ed

0 Kudos