title: python requests keep connection alive for indefinite time
body: <p>I'm trying to get a python script running which calls an external API (to which I only have read-access) in a certain interval, the API uses cookie-based authentication: Calling the <code>/auth</code> endpoint initially sets session cookies which are then used for authentication in further requests. </p>
  
  <p>As for my problem: Because the authentication is based on an active session, the cookies aren't valid once the connection drops, and therefore has to be restarted. From what I've read, <code>requests</code> is based on <code>urllib3</code>, which keeps the connection alive by default. Yet, after a few tests I noticed that under some circumstances, the connection will be dropped anyway.</p>
  
  <p>I used a <code>Session</code> object from the <code>requests</code> module and I've tested how long it takes for the connection to be dropped as follows:</p>
  
  <pre><code>from requests import session
  import logging
  import time import time, sleep
  
  logging.basicConfig(level=logging.DEBUG)
  
  def tt(interval):
      credentials = {"username":"user","password":"pass"}
      s = Session()
      r = s.post("https://&lt;host&gt;:&lt;port&gt;/auth", json=credentials)
      ts = time()
      while r.status_code is 200:
          r = s.get("https://&lt;host&gt;:&lt;port&gt;/some/other/endpoint")
          sleep(interval)
      return time() - ts # Seconds until connection drop
  </code></pre>
  
  <p>Might not be the best way to find that out, but I let that function run twice, once with an interval of 1 second and then with an interval of 1 minute. Both had run for about an hour until I had to manually stop the execution. </p>
  
  <p>However, when I swapped the two lines within the <code>while</code> loop, which meant that there was a 1-minute-delay after the initial <code>POST /auth</code> request, the following <code>GET</code> request failed with a <code>401 Unauthorized</code> and this message being logged beforehand:</p>
  
  <pre><code>DEBUG:urllib3.connectionpool:Resetting dropped connection: &lt;host&gt;
  </code></pre>
  
  <p>As the interval of requests may range from a few minutes to multiple hours in my prod script, I have to know beforehand how long these sessions are kept alive and whether there are some exceptions to that rule (like dropping the connection if no request after the initial <code>POST /auth</code> is made for a short while). </p>
  
  <p>So, how long does <code>requests</code> or rather <code>urllib3</code> keep the connection alive, and is it possible to extend that time indefinitely? </p>
  
  <p>Or is it the server instead of <code>requests</code> that drops the connection?</p>