title: Python Requests Error ('Connection aborted.', OSError(0, 'error')) and Connection timeout in scale
body: <p>I'm trying to scrape the redfish API on an ip range using django and python to figure out all the ips that has redfish enabled. It works well when I'm doing discovery one ip by one ip, but encountered Connection error issues in scale.</p>
  
  <p>This is the sample code that I used to simulate the error:</p>
  
  <pre><code>def thread_func(ip_resource, sem):
      import requests
      def get_auth_token(ip, brand, redfish_user, redfish_password):
          s = requests.Session()
          headers = {"content-type": "application/json"}
          url = "https://{}/redfish/v1/SessionService/Sessions".format(ip)
          r = s.post(
              url,
              json={"UserName": redfish_user, "Password": redfish_password},
              headers=headers,
              timeout=120,
              verify=False,
          )
  
          if r.status_code == 201:
              s.headers.update({'X-Auth-Token': r.headers['X-Auth-Token']})
              return r.headers['Location'], r.headers['X-Auth-Token'], s
          else:
              return "", "", None
  
      def delete_token(ip, location, auth_token, session):
          headers = {"content-type": "application/json", "X-Auth-Token": auth_token}
          url = "https://{}{}".format(ip, location)
          r = session.delete(
              url,
              headers=headers,
              timeout=120,
              verify=False,
          )
          session.close()
      with sem:
          print("ENTERED")
          try:
              location, token, session = get_auth_token(ip_resource.ip, ip_resource.brand, ip_resource.redfish_user, ip_resource.redfish_password)
              if location != "":
                  r = session.get(
                      "https://{}/redfish/v1/Systems".format(ip_resource.ip),
                      timeout=120,
                      verify=False,
                  )
                  if r.status_code is None or r.status_code &lt; 200 or r.status_code &gt; 299:
                      print("Request 1 Error")
                      return
  
                  computer_system_resource_url = r.json()["Members"][0]["@odata.id"]
                  r2 = session.get(
                      "https://{}{}".format(ip_resource.ip, computer_system_resource_url),
                      timeout=120,
                      verify=False,
                  )
                  if r2.status_code is None or r2.status_code &lt; 200 or r2.status_code &gt; 299:
                      print("Request 2 Error")
                  delete_token(ip_resource.ip, location, token, session)
              else:
                  print("Cannot get token")
          except requests.exceptions.ConnectionError as e:
              print("Errors: " + str(e))
  semaphore = threading.Semaphore(50)
  for ip_resource in ip_resources:
      s = threading.Thread(target=thread_func, args=(ip_resource,semaphore))
      threads.append(s)
      s.start()
  </code></pre>
  
  <p>At scale, I have around 7k ips in <code>ip_resources</code>. And they will have Connection Errors randomly. The two errors that popped up are:
  <code>('Connection aborted.', OSError(0, 'Error'))</code> and <code>HTTPSConnectionPool(host='x.x.x.x', port=443): Max retries exceeded with url: /redfish/v1/SessionService/Sessions (Caused by ConnectTimeoutError(&lt;urllib3.connection.VerifiedHTTPSConnection object at 0x7fca78229208&gt;, 'Connection to x.x.x.x timed out. (connect timeout=120)'))</code></p>
  
  <p>I don't think I have reached the limit of tcp connection, since it's at most 7k connections and I'm using sessions to reuse the connection.</p>