Getting intermittent connection errors when using Python on the search APIs



I am using Python to get search results on a specific topic from twitter.
I run my search query once every 5 minutes, using cron, so Python closes up and then reopens every 5 minutes.
I use OAuth2Service library for python.

The service works perfectly well, but every once in a while (=2-20 times a day), returns with a connection error, similar to the below:

Traceback (most recent call last):
File "./", line 43, in 
File "/usr/local/lib/python2.7/dist-packages/requests-2.1.0-py2.7.egg/requests/", line 424, in post
return self.request('POST', url, data=data, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/rauth-0.6.2-py2.7.egg/rauth/", line 368, in request
return super(OAuth2Session, self).request(method, url, **req_kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests-2.1.0-py2.7.egg/requests/", line 382, in request
resp = self.send(prep, **send_kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests-2.1.0-py2.7.egg/requests/", line 485, in send
r = adapter.send(request, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/requests-2.1.0-py2.7.egg/requests/", line 372, in send
raise ConnectionError(e)
ConnectionError: HTTPSConnectionPool(host='', port=443): Max retries exceeded with url: /oauth2/token (Caused by : [Errno -2] Name or service not known)

Any idea why?
What can I do to fix this, or at the very least reduce the error rate?



Seems your DNS provider or connectivity to internet is unreachable from the machine for that moment. It has nothing to do with Twitter servers.


I got similar error on facebook api and resolved it by adding Host header to the request.


If connectivity to internet is unreachable then it should be connected after sometime right? But it is not getting connected. I have been trying to solve this issue from one day.Can you please help me to resolve this?