<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Using Python with Integrated Windows Authentication  in ArcGIS Enterprise Questions</title>
    <link>https://community.esri.com/t5/arcgis-enterprise-questions/using-python-with-integrated-windows/m-p/25897#M946</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I had never heard of portalpy. I found it, but the page says it's been deprecated. &lt;/P&gt;&lt;P&gt;PortalPy:&amp;nbsp; &lt;A class="link-titled" href="https://github.com/Esri/portalpy" title="https://github.com/Esri/portalpy"&gt;GitHub - Esri/portalpy: A module that allows you to administer Portal for ArcGIS and ArcGIS Online.&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 26 Nov 2018 21:57:03 GMT</pubDate>
    <dc:creator>davedoesgis</dc:creator>
    <dc:date>2018-11-26T21:57:03Z</dc:date>
    <item>
      <title>Using Python with Integrated Windows Authentication</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-questions/using-python-with-integrated-windows/m-p/25895#M944</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Our ArcGIS Server 10.31 uses Integrated Windows Authentication (IWA). I am able to access everything using a web browser without ever logging in. It's really seamless. The problem I'm having is getting some Python code to access the REST admin URLs (using urllib, requests, or similar), e.g.:&amp;nbsp;&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new, courier, monospace;"&gt;&lt;A class="unlinked"&gt;http://[domain]/arcgis/&lt;SPAN style="color: #ff0000;"&gt;&lt;STRONG&gt;admin&lt;/STRONG&gt;&lt;/SPAN&gt;/security/users/search&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When Python runs, it doesn't take advantage of the Integrated Windows Authentication. The response I get is a 401 with the body HTML saying:&lt;/P&gt;&lt;P style="padding-left: 30px;"&gt;&lt;SPAN style="font-family: courier new, courier, monospace;"&gt;401 - Unauthorized: Access is denied due to invalid credentials. &lt;/SPAN&gt;&lt;SPAN style="font-family: courier new, courier, monospace;"&gt;You do not have permission to view this directory or page using the credentials that you supplied.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have tried just about every iteration of passing in POST parameters, headers, and cookies with the python urllib and requests modules. I have tried passing in my user/pass, a token I generated, and also tokens that I fish out of Firefox's request/response stream. I may not have exhausted every possible combination, but I've given it the good ole' college try and come up empty. If anyone knows how to access the REST Admin URLs from Python (under IWA), I'd appreciate the help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Another thought I had is that tokens and logins are going about this the wrong way. Is there some way to get Python to use my IWA identity and run as me, just like Firefox and Internet Explorer do? That could be a more elegant solution, since I wouldn't have to fool around with generating tokens or sending a user/pass around.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 22 Nov 2018 00:32:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-questions/using-python-with-integrated-windows/m-p/25895#M944</guid>
      <dc:creator>davedoesgis</dc:creator>
      <dc:date>2018-11-22T00:32:30Z</dc:date>
    </item>
    <item>
      <title>Re: Using Python with Integrated Windows Authentication</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-questions/using-python-with-integrated-windows/m-p/25896#M945</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you can get away with it, I would recommend using the python api.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://developers.arcgis.com/python/"&gt;https://developers.arcgis.com/python/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Otherwise, I would use portalpy.&lt;/P&gt;&lt;P&gt;&lt;A href="https://enterprise.arcgis.com/en/portal/latest/administer/windows/portalpy-module.htm"&gt;https://enterprise.arcgis.com/en/portal/latest/administer/windows/portalpy-module.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If none of the above can get it done, then yes, you will need to delve into requests, encoding etc.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 22 Nov 2018 02:29:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-questions/using-python-with-integrated-windows/m-p/25896#M945</guid>
      <dc:creator>AngusHooper1</dc:creator>
      <dc:date>2018-11-22T02:29:12Z</dc:date>
    </item>
    <item>
      <title>Re: Using Python with Integrated Windows Authentication</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-questions/using-python-with-integrated-windows/m-p/25897#M946</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I had never heard of portalpy. I found it, but the page says it's been deprecated. &lt;/P&gt;&lt;P&gt;PortalPy:&amp;nbsp; &lt;A class="link-titled" href="https://github.com/Esri/portalpy" title="https://github.com/Esri/portalpy"&gt;GitHub - Esri/portalpy: A module that allows you to administer Portal for ArcGIS and ArcGIS Online.&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 26 Nov 2018 21:57:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-questions/using-python-with-integrated-windows/m-p/25897#M946</guid>
      <dc:creator>davedoesgis</dc:creator>
      <dc:date>2018-11-26T21:57:03Z</dc:date>
    </item>
    <item>
      <title>Re: Using Python with Integrated Windows Authentication</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-questions/using-python-with-integrated-windows/m-p/25898#M947</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here is how I solved it (kind of). I have to give it a user/pass, which means I need to either enter that every time it runs (can't be automated) or store it somewhere in a file on my computer (questionable security practice). The good news is I don't have to fool around with tokens.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Since I don't specify anything that when connecting with a browser, I feel like this is still sub-optimal. Does anyone know how to get Python to run as my user without me having to enter my user/password? Internet Explorer works with ArcGIS Server natively. I had to explicitly tell Firefox to trust my org's domain in order to activate Integrated Windows Authentication. Is there something like that for Python? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Without further ado, here is how I (kind of) solved this:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="color: #339966;"&gt;import json&lt;/SPAN&gt;
&lt;SPAN style="color: #339966;"&gt;import requests&lt;/SPAN&gt;
&lt;SPAN style="color: #339966;"&gt;from requests_ntlm import HttpNtlmAuth&lt;/SPAN&gt;
&lt;SPAN style="color: #339966;"&gt;server_root = '&lt;A class="unlinked" style="color: #339966;" target="_blank"&gt;http://your_domain/arcgis/admin/&lt;/A&gt;&amp;nbsp;'&lt;/SPAN&gt;
&lt;SPAN style="color: #339966;"&gt;role_url = server_root + 'security/roles/getUsersWithinRole'&lt;/SPAN&gt;
&lt;SPAN style="color: #339966;"&gt;role_name = 'your_role'&lt;/SPAN&gt;
&lt;SPAN style="color: #339966;"&gt;ntlm_user = 'your_user'&lt;/SPAN&gt;
&lt;SPAN style="color: #339966;"&gt;ntlm_pass = 'your_password'&lt;/SPAN&gt;
&lt;SPAN style="color: #339966;"&gt;params = {'rolename': role_name, 'f': 'pjson'}&lt;/SPAN&gt;
&lt;SPAN style="color: #339966;"&gt;ehp_users_response = requests.post(&lt;/SPAN&gt;
&lt;SPAN style="color: #339966;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; role_url, data=params,&lt;/SPAN&gt;
&lt;SPAN style="color: #339966;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; auth=HttpNtlmAuth(ntlm_user, ntlm_pass))&lt;/SPAN&gt;


&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 15:55:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-questions/using-python-with-integrated-windows/m-p/25898#M947</guid>
      <dc:creator>davedoesgis</dc:creator>
      <dc:date>2021-12-12T15:55:41Z</dc:date>
    </item>
    <item>
      <title>Re: Using Python with Integrated Windows Authentication</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-questions/using-python-with-integrated-windows/m-p/25899#M948</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Have you tried &lt;A class="link-titled" href="https://github.com/brandond/requests-negotiate-sspi" title="https://github.com/brandond/requests-negotiate-sspi"&gt;GitHub - brandond/requests-negotiate-sspi: Windows SSPI-based Negotiate authentication support for Requests.&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 26 Nov 2018 22:29:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-questions/using-python-with-integrated-windows/m-p/25899#M948</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2018-11-26T22:29:19Z</dc:date>
    </item>
    <item>
      <title>Re: Using Python with Integrated Windows Authentication</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-questions/using-python-with-integrated-windows/m-p/25900#M949</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That did it, thanks!!! No user/pass needed.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;With the code above, add this import:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="color: #339966;"&gt;from requests_negotiate_sspi import HttpNegotiateAuth&lt;/SPAN&gt;
&lt;/PRE&gt;&lt;P&gt;Then, update the requests.post with the following code:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="color: #339966;"&gt;ehp_users_response = requests.post(&lt;/SPAN&gt;
&lt;SPAN style="color: #339966;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; role_url, data=params, auth=&lt;SPAN style="color: #008000;"&gt;&lt;STRONG&gt;HttpNegotiateAuth()&lt;/STRONG&gt;&lt;/SPAN&gt;)&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 15:55:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-questions/using-python-with-integrated-windows/m-p/25900#M949</guid>
      <dc:creator>davedoesgis</dc:creator>
      <dc:date>2021-12-12T15:55:44Z</dc:date>
    </item>
    <item>
      <title>Re: Using Python with Integrated Windows Authentication</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-questions/using-python-with-integrated-windows/m-p/25901#M950</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Glad it worked for you.&amp;nbsp; I had a similar question a while back and was surprised to find how it wasn't more baked into Requests itself.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Nov 2018 14:57:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-questions/using-python-with-integrated-windows/m-p/25901#M950</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2018-11-27T14:57:11Z</dc:date>
    </item>
    <item>
      <title>Re: Using Python with Integrated Windows Authentication</title>
      <link>https://community.esri.com/t5/arcgis-enterprise-questions/using-python-with-integrated-windows/m-p/1303788#M36359</link>
      <description>&lt;P&gt;&lt;A href="https://developers.arcgis.com/python/guide/working-with-different-authentication-schemes/#web-tier-authentication-secured-with-iwa" target="_blank"&gt;Working with different authentication schemes | ArcGIS API for Python&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jun 2023 07:23:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-enterprise-questions/using-python-with-integrated-windows/m-p/1303788#M36359</guid>
      <dc:creator>SimonSchütte_ct</dc:creator>
      <dc:date>2023-06-28T07:23:09Z</dc:date>
    </item>
  </channel>
</rss>

