title: API Connection using Python requests_kerberos
body: <p>This is my first experience trying to connect to an API through python (from windows) using Kerberos authentication. I have been working on it for a few days and my progress has stalled. Here are just a few of the references I have been using:</p>
  <p>This is the best tutorial I have found, but it appears to be using a deprecated module rather than the requests_kerberos:
  <a href="http://python-notes.curiousefficiency.org/en/latest/python_kerberos.html" rel="nofollow noreferrer">http://python-notes.curiousefficiency.org/en/latest/python_kerberos.html</a></p>
  <p><a href="https://pypi.org/project/requests-kerberos/" rel="nofollow noreferrer">https://pypi.org/project/requests-kerberos/</a></p>
  <p><a href="https://programtalk.com/python-examples/requests_kerberos.HTTPKerberosAuth/" rel="nofollow noreferrer">https://programtalk.com/python-examples/requests_kerberos.HTTPKerberosAuth/</a></p>
  <p>Here is what I have tried so far(I will be masking sensitive information):</p>
  <pre><code>import requests
  from requests_kerberos import HTTPKerberosAuth
  r=requests.get(&quot;https://apiServer.hadoop.company.com:23232/templeton/v1/ddl/database/&quot;,auth=HTTPSKerberosAuth)
  </code></pre>
  <p>Here is some output:</p>
  <pre><code>r.status_code
  </code></pre>
  <blockquote>
  <p>401</p>
  </blockquote>
  <pre><code>r.headers
  </code></pre>
  <blockquote>
  <p>{'Content-Length': '1321', 'Set-Cookie': 'hadoop.auth=; Path=/; HttpOnly', 'Server': 'Jetty(7.6.0.v20120127)', 'Cache-Control': 'must-revalidate,no-cache,no-store', 'Content-Type': 'text/html;charset=ISO-8859-1', 'WWW-Authenticate': 'Negotiate'}</p>
  </blockquote>
  <pre><code>r.text
  
  &lt;html&gt;\n&lt;head&gt;\n&lt;meta http-equiv=&quot;Content-Type&quot; 
  content=&quot;text/html;charset=ISO
  -8859-1&quot;/&gt;\n&lt;title&gt;Error 401 Authentication 
  required&lt;/title&gt;\n&lt;/head&gt;\n&lt;body&gt;\n&lt;
  h2&gt;HTTP ERROR: 401&lt;/h2&gt;\n&lt;p&gt;Problem accessing /templeton/v1/ddl/database/. 
  Reason:\n&lt;pre&gt;    Authentication required&lt;/pre&gt;&lt;/p&gt;\n&lt;hr /&gt;&lt;i&gt;&lt;small&gt;Powered 
  by Jetty://&lt;/small&gt;&lt;/i&gt;
  </code></pre>
  <p><strong>Does any of this output at least indicate that the server is getting my request?</strong></p>
  <p>If I connect to the API from our linux environment using curl it works just fine and I receive the expected output:</p>
  <pre><code>curl --negotiate -i -u :  'http://apiServer.hadoop.company.com:23232/templeton/v1/ddl/database/'
  </code></pre>
  <blockquote>
  <p>HTTP/1.1 401 Authentication required
  WWW-Authenticate: Negotiate
  Set-Cookie: hadoop.auth=; Path=/; HttpOnly
  Cache-Control: must-revalidate,no-cache,no-store
  Content-Type: text/html;charset=ISO-8859-1
  Content-Length: 1321
  Server: Jetty(7.6.0.v20230127)</p>
  <p>HTTP/1.1 200 OK
  WWW-Authenticate: Negotiate YGY1cwVaADAgCAQ+iSTBHoAMCAReiQAQ+sf/nekePw09B/cboDrINa7qn+aENRuw2V+OW7Y7Rk9pOwGa8hrXC3rXKxCk=
  Set-Cookie: hadoop.auth=&quot;u=svc-qa-dsafqa-dev&amp;p=svc-fd-itdflea-dev@hadoop.company.com&amp;t=kerberos&amp;e=15392343251&amp;s=nWk/bFDbHQfsadfewe8PtjAsVHs=&quot;; Path=/; HttpOnly
  Content-Type: application/json
  Transfer-Encoding: chunked
  Server: Jetty(7.6.0.v20120127)</p>
  </blockquote>
  <p>I realize that there is a gap in my fundamental understanding of kerberos authentication and I'm trying to bring to do a crash course, but I really just need to be able to connect to this api. Any help is greatly appreciated.</p>