Python API can't connect to portal with windows authentication

9635
14
09-03-2017 06:10 PM
simoxu
by MVP Regular Contributor
MVP Regular Contributor

Hi folks,

I am new to this API, I tried it with ArcGIS Online it works fine. But when I try to connect to our local ArcGIS portal, it doesn't work. Can anybody kindly point me to the right direction? I highly suspect that the problem is the API can't pick up my windows credentials which is required to login the portal.

More information:

Our portal is using IWA authentication, and this document for IWA points to not using a username or password:

 

It looks like there are some additional requirements for using IWA and the ArcGIS Python API:

"If your portal is configured to pick up your Windows credeintials using NTLM or Kerberos, you can omit passing in the username and password. The ArcGIS Python API is able to figure out when the GIS is using Windows authentication and picks the login credentials from the currently running process providing a seamless and secure login experience. Windows authentication only works on the Windows OS and requires pywin32 and kerberos-sspi python packages."

Please see the screen dump for details: (click to zoom in)

 

 

Tags (2)
14 Replies
RohitSingh2
Esri Contributor

Hello Simo,

I have come across a case when the portal was actually configured to use SAML. 

To rule that out, can you try the following:

  • Log into your web GIS (ArcGIS Online organization or ArcGIS Enterprise) in the browser
  • Go to Content tab
  • Click '+ Add Item > An Application' menu
  • Add an application:
    • Type: Application
    • Title: Python
    • Tags: python
  • On the Item details page of this newly created application, navigate to Settings tab
  • Click the Registered Info button. It's towards the bottom of the page.
  • This will show an App ID. This is your client id and needs to be passed in as the client_id parameter when constructing a GIS object. You need this in your Python code to log in

 

Example code:

test_client_id = 'OGz1I2eoO8dO0ii2' #replace with your client id

gis = GIS('https://your portal url', client_id=test_client_id)

gis.users.me

simoxu
by MVP Regular Contributor
MVP Regular Contributor

Hello Rohit,

Thank you so much for your reply.

I tested as you suggested, but the problem remains. I double checked with the administrator, we are using IWA, not SAML.

I not only tested in Jupyter notebook, I also tried in python IDE (Wing IDE) to make direct connections to the portal, but it was not successful.

Surely there is something wrong on our server, just don't know where to look at. I checked it with this document, Use Integrated Windows Authentication with your portal—Portal for ArcGIS (10.5.x) | ArcGIS Enterpris... , nothing looks suspicious in the server settings.

Update:  I just tried the python window in ArcGIS Pro, I can login our portal from there omitting the username and password ---- and I print out the user information, it seems the API picked up my windows login inside of ArcGIS Pro. Python window in Pro is not the ideal environment for me to do my tasks.

simoxu
by MVP Regular Contributor
MVP Regular Contributor

After I overwrote the arcgis related packages under anaconda3 using the packages under ArcGIS pro, everything seems working fine.

The packages installed by conda is slightly different from those installed by ArcGIS Pro...

don't know why, but It's working, I am happy

Update: the working version is version 1.0.1 on Python 3.5 .... I am missing out lots of latest features tho.

simoxu
by MVP Regular Contributor
MVP Regular Contributor

OK, it is a bug for 1.2.0, 1.2.1, 1.2.2, 1.2.3 and finally addressed in the latest release of 1.2.4! well, sort of...

BUG-000108063: ArcGIS API for Python is unable to connect to Portal.. 

The bug was only submitted on Sep 15 and I reported the issue as a comment on the 1.2.0 release announcement on Sep 11. coincident?

DavidJones12
New Contributor II

Hi simo xu,

I think I may be experiencing a similar issue. Can you provide some detail on what you meant when you said "I overwrote the arcgis related packages under anaconda3 using the packages under ArcGIS pro"? I don't currently have Anaconda3 installed. I have Anaconda 2, and toggle between environments with settings in my IDE. Any assistance would be appreciated.

Thanks,

David

JoeHershman
MVP Regular Contributor

Python API requires python 3.5+

Thanks,
-Joe
0 Kudos
DavidJones12
New Contributor II

Hi Joe,

Yeah, that's not my problem. I have multiple Python environments and successfully switch between them and have successfully used the Python API for other actions. I'm trying to connect to a secure ArcGIS Enterprise service and having no luck. I've successfully accessed secure hosted services before, but just updated Pro and wondering if something went awry. I was curious what the original poster meant by replacing arcgis related packages under Anaconda3 using the packages under ArcGIS Pro. I'm not seeing an Anaconda3 set of things under my Pro folder, and don't have A3 installed. I'm assuming the original poster did have A3 installed and worked to get the API dependencies setup with it also. Not sure...

David

JoeHershman
MVP Regular Contributor

I did the same thing as he did to get it to work with an Aneconda install.  One thing you could do is just use the ArcGIS Pro install of python and add the packages for the python API (can event do with the Pro tools).  What I did was copy the files in the /lib folder from a pro installation to the /lib folder in my Anecoda install.  Not sure why but this fixed the issue with connecting using single sign on AD.  I have had weird behavior with install, sometimes it has worked right off the bat, another I had to do as the original poster describes.

Thanks,
-Joe
DavidJones12
New Contributor II

Light bulb! Thanks. That's a good idea. I'll give it a try.

0 Kudos