I have an ArcGIS Portal log in account (viewer account) in an enterprise GIS infrastructure and want to use the ArcGIS Python API to connect with a separate admin account to be able to produce reports on the ArcGIS Portal instance (layers being used in web maps, user last login stats etc).

When trying to connect using an admin account, it automatically connects with my viewer account (I am assuming my account is somehow automatically authorised within my network).

How am I able to explicitly log in with a different account using the ArcGIS Python API?

My script is below:

from arcgis.gis import GIS
import getpass

password = getpass.getpass("Enter password: ")
gis = GIS("https://myserver", "myadminaccount", password)
print("Connected as: " + gis.properties.user.username + " on " + gis.properties.customBaseUrl)
  • It would be helpful to see what your script is.
    – enolan
    Dec 31, 2019 at 13:10
  • @enolan I have added the script; so I specify an admin account but the account it displays as being connected is my viewer account.
    – Chris
    Dec 31, 2019 at 13:22
  • Check out my answer below one of those scenarios will help, and if not I also posted the developer link for the GIS library.
    – enolan
    Dec 31, 2019 at 13:23

1 Answer 1


There is a specific python library that you need to import:

# import the GIS class in gis module
from arcgis.gis import GIS

I suggest for the following code snippets that you use the print function so you know what account you are logging in with, and what code affects your credentials so you fully understand.

You can print what your logged in as (just to make sure while testing/troubleshooting):

print("Logged in as " + str(gis.properties.user.username))

To log in with a built-in account then use the following code (this for an account that is setup in ArcGIS Server under users and given a role):

print("Portal for ArcGIS as a built in user")
gis = GIS("https://portalname.domain.com/webadapter_name", "sharinguser", "password")
print("Logged in as: " + gis.properties.user.username)

If you want to log in with Web-tier authentication then use the following code:

print("\n\nBasic Authentication with LDAP")    
ldapbasic = GIS("https://portalname.domain.com/webadapter_name", "amy", "password")
print("Logged in as: " + ldapbasic.properties.user.username)

If you want to use Portal account log in credentials then use the following code:

print("\n\nPortal-tier Authentication with LDAP - enterprise user")
gisldap = GIS("https://portalname.domain.com/webadapter_name", "AVWORLD\\Publisher", "password")
print("Logged in as: " + gisldap.properties.user.username)

And if you want to use Portal with LDAP (so your network account that you maybe be referring to) then use this code:

print("\n\nPortal-tier Authentication with LDAP - builtin user")    
gisldap = GIS("https://portalname.domain.com/webadapter_name", "sharing1", "password")
print("Logged in as: " + gisldap.properties.user.username)

If you don't have success with the above, or have a different authorization pattern follow this link:


  • Thank you @enolan, I edited my original question to include my code which does import the GIS module and includes the admin account I want to use, but it uses my viewer account.
    – Chris
    Dec 31, 2019 at 13:23
  • Log out of all portal sessions that you have open in browsers. Close out all browser sessions. And then try, if this works then I would consider that a bug. I would not that in your code that you have myserver, so we can't really tell what it is that you are connecting to, it should be your portal instance.
    – enolan
    Dec 31, 2019 at 13:44
  • Yes it is my portal instance, I just put that in there to remove the actual server path. When opening the portal in a web browser I am already logged in, I am unable to log out as I see nowhere where I can, is that normal?
    – Chris
    Dec 31, 2019 at 14:23
  • When I login using gis = GIS('pro'), I am able to login successfully with my enterprise login. However, when I login with with gis = GIS(portal, username, password), my login fails. I can use the built-in account to login but not my enterprise account. My password is same as my organization password. Also, it states that i must include a webadaptor_name with my portal link. I am not sure what it is or where to find it. While logging in successfully using gis = GIS('pro'), printing GetActivePortalURL() gives a link without a webadaptor_name. Any pointers?
    – April
    Feb 28, 2020 at 16:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.