When trying to send a large number of requests (>500), I get a connection error like so:
ConnectionError: ('Connection aborted.', gaierror(8, 'nodename nor servname provided, or not known'))
The code:
   def compare_and_fix(mac, reqSession):
        url = hosturl + <api as a string> + mac
        try:
                resp = json.loads(reqSession.get(url, headers=headers, cert=(…), timeout=10, verify=False).text)
                response_code = resp['status']
                if response_code == 200:
                        result = resp['data']
                else:
                        print “oo-ooh!”
        except Exception as ex:
                print ex.message
    def worker(reqSession):
            while True:
                    mac = q.get()
                    if validate_mac(mac):
                            compare_and_fix(mac, reqSession)
                    q.task_done()
    num_worker_threads=500
    q = Queue()
    for i in range(num_worker_threads):
            session = requests.session().client()
            t = Thread(target=worker, args=(session,))
            t.daemon = True
            t.start()
    for mac in mac_list:
            q.put(mac)
    print "Waiting for threads to join"                                                                                                                                                                 
    q.join()
This works well if num_worker_threads is low ~100-200. Anything more, and I start to see the above error. If I go more than 500, I see it happen quite a bit (~15% of all calls fail with this error at this point).
Trace:
    exception : Traceback (most recent call last):   
        File “xyz.py", line 62, in abc
                resp = json.loads(reqSession.get(url, headers=headers, cert=(…), timeout=10, verify=False).text)   
        File "/Library/Python/2.7/site-packages/requests/sessions.py", line 476, in get
                return self.request('GET', url, **kwargs)   
        File "/Library/Python/2.7/site-packages/requests/sessions.py", line 464, in request
                resp = self.send(prep, **send_kwargs)   
        File "/Library/Python/2.7/site-packages/requests/sessions.py", line 576, in send
                r = adapter.send(request, **kwargs)   
        File "/Library/Python/2.7/site-packages/requests/adapters.py", line 415, in send 
    ConnectionError: ('Connection aborted.', gaierror(8, 'nodename nor servname provided, or not known'))
Any insight into this issue is appreciated. Thanks!