title: How do I use basic HTTP authentication with the python Requests library?
body: <p>I'm trying to use basic HTTP authentication in python. I am using the <a href="https://docs.python-requests.org/" rel="noreferrer">Requests library</a>:</p>
  <pre><code>auth = requests.post('http://' + hostname, auth=HTTPBasicAuth(user, password))
  request = requests.get('http://' + hostname + '/rest/applications')
  </code></pre>
  <p>Response form <b>auth</b> variable:<br></p>
  <pre><code>&lt;&lt;class 'requests.cookies.RequestsCookieJar'&gt;[&lt;Cookie JSESSIONID=cb10906c6219c07f887dff5312fb for appdynamics/controller&gt;]&gt;
  200
  CaseInsensitiveDict({'content-encoding': 'gzip', 'x-powered-by': 'JSP/2.2', 'transfer-encoding': 'chunked', 'set-cookie': 'JSESSIONID=cb10906c6219c07f887dff5312fb; Path=/controller; HttpOnly', 'expires': 'Wed, 05 Nov 2014 19:03:37 GMT', 'server': 'nginx/1.1.19', 'connection': 'keep-alive', 'pragma': 'no-cache', 'cache-control': 'max-age=78000', 'date': 'Tue, 04 Nov 2014 21:23:37 GMT', 'content-type': 'text/html;charset=ISO-8859-1'})
  </code></pre>
  <p>But when I try to get data from different location, - I'm got 401 error</p>
  <pre><code>&lt;&lt;class 'requests.cookies.RequestsCookieJar'&gt;[]&gt;
  401
  CaseInsensitiveDict({'content-length': '1073', 'x-powered-by': 'Servlet/3.0 JSP/2.2 (GlassFish Server Open Source Edition 3.1.2.2 Java/Oracle Corporation/1.7)', 'expires': 'Thu, 01 Jan 1970 00:00:00 UTC', 'server': 'nginx/1.1.19', 'connection': 'keep-alive', 'pragma': 'No-cache', 'cache-control': 'no-cache', 'date': 'Tue, 04 Nov 2014 21:23:37 GMT', 'content-type': 'text/html', 'www-authenticate': 'Basic realm=&quot;controller_realm&quot;'})
  </code></pre>
  <p>As far as I understand - in second request are not substituted session parameters.</p>