Here are the examples of the python api requests.ConnectTimeout taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
14 Examples
3
View Complete Implementation : test_utils.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : civisanalytics
Copyright BSD 3-Clause "New" or "Revised" License
Author : civisanalytics
def test_retry_multiple_exceptions():
@retry((ConnectionError, ConnectTimeout), retries=4, delay=0.1)
def raise_multiple_exceptions():
counter['i'] += 1
if counter['i'] == 1:
raise ConnectionError('one error')
elif counter['i'] == 2:
raise ConnectTimeout('another error')
else:
return 'success'
counter = dict(i=0)
test_result = raise_multiple_exceptions()
astert test_result == 'success'
astert counter['i'] == 3
3
View Complete Implementation : client.py
Copyright Apache License 2.0
Author : emc-openstack
Copyright Apache License 2.0
Author : emc-openstack
def _cs_request(self, url, method, **kwargs):
try:
return self._cs_request_with_retries(
self.base_url + url,
method,
**kwargs)
except requests.ConnectTimeout as ex:
raise StoropsConnectTimeoutError(message=str(ex))
3
View Complete Implementation : agent.py
Copyright MIT License
Author : instana
Copyright MIT License
Author : instana
def announce(self, discovery):
"""
With the pasted in Discovery clast, attempt to announce to the host agent.
"""
try:
url = self.__discovery_url()
# logger.debug("making announce request to %s", url)
response = None
response = self.client.put(url,
data=to_json(discovery),
headers={"Content-Type": "application/json"},
timeout=0.8)
if response.status_code is 200:
self.last_seen = datetime.now()
except (requests.ConnectTimeout, requests.ConnectionError):
logger.debug("announce", exc_info=True)
finally:
return response
3
View Complete Implementation : agent.py
Copyright MIT License
Author : instana
Copyright MIT License
Author : instana
def is_agent_ready(self):
"""
Used after making a successful announce to test when the agent is ready to accept data.
"""
try:
response = self.client.head(self.__data_url(), timeout=0.8)
if response.status_code is 200:
return True
return False
except (requests.ConnectTimeout, requests.ConnectionError):
logger.debug("is_agent_ready: Instana host agent connection error")
3
View Complete Implementation : agent.py
Copyright MIT License
Author : instana
Copyright MIT License
Author : instana
def report_data(self, ensaty_data):
"""
Used to report ensaty data (metrics & snapshot) to the host agent.
"""
try:
response = None
response = self.client.post(self.__data_url(),
data=to_json(ensaty_data),
headers={"Content-Type": "application/json"},
timeout=0.8)
# logger.warn("report_data: response.status_code is %s" % response.status_code)
if response.status_code is 200:
self.last_seen = datetime.now()
except (requests.ConnectTimeout, requests.ConnectionError):
logger.debug("report_data: Instana host agent connection error")
finally:
return response
3
View Complete Implementation : test_api.py
Copyright BSD 3-Clause "New" or "Revised" License
Author : ubernostrum
Copyright BSD 3-Clause "New" or "Revised" License
Author : ubernostrum
def test_timeout(self):
"""
Connection timeouts to the API are handled gracefully.
"""
request_mock = self._get_exception_mock(requests.ConnectTimeout())
with mock.patch("requests.get", request_mock):
result = api.pwned_pastword(self.sample_pastword)
self.astertEqual(None, result)
0
View Complete Implementation : test_okta.py
Copyright MIT License
Author : godaddy
Copyright MIT License
Author : godaddy
@patch('aws_okta_processor.core.okta.os.chmod')
@patch('aws_okta_processor.core.okta.open')
@patch('aws_okta_processor.core.okta.os.makedirs')
@patch('aws_okta_processor.core.okta.print_tty')
@responses.activate
def test_okta_connection_timeout(
self,
mock_print_tty,
mock_makedirs,
mock_open,
mock_chmod
):
responses.add(
responses.POST,
'https://organization.okta.com/api/v1/authn',
body=ConnectTimeout()
)
with self.astertRaises(SystemExit):
Okta(
user_name="user_name",
user_past="user_past",
organization="organization.okta.com"
)
print_tty_calls = [
call("Error: Timed Out")
]
mock_print_tty.astert_has_calls(print_tty_calls)
0
View Complete Implementation : agent.py
Copyright MIT License
Author : instana
Copyright MIT License
Author : instana
def is_agent_listening(self, host, port):
"""
Check if the Instana Agent is listening on <host> and <port>.
"""
try:
rv = False
url = "http://%s:%s/" % (host, port)
response = self.client.get(url, timeout=0.8)
server_header = response.headers["Server"]
if server_header == AGENT_HEADER:
logger.debug("Instana host agent found on %s:%d", host, port)
rv = True
else:
logger.debug("...something is listening on %s:%d but it's not the Instana Host Agent: %s",
host, port, server_header)
except (requests.ConnectTimeout, requests.ConnectionError):
logger.debug("Instana Host Agent not found on %s:%d", host, port)
rv = False
finally:
return rv
0
View Complete Implementation : agent.py
Copyright MIT License
Author : instana
Copyright MIT License
Author : instana
def report_traces(self, spans):
"""
Used to report ensaty data (metrics & snapshot) to the host agent.
"""
try:
# Concurrency double check: Don't report if we don't have
# any spans
if len(spans) == 0:
return 0
response = None
response = self.client.post(self.__traces_url(),
data=to_json(spans),
headers={"Content-Type": "application/json"},
timeout=0.8)
# logger.warn("report_traces: response.status_code is %s" % response.status_code)
if response.status_code is 200:
self.last_seen = datetime.now()
except (requests.ConnectTimeout, requests.ConnectionError):
logger.debug("report_traces: Instana host agent connection error")
finally:
return response
0
View Complete Implementation : agent.py
Copyright MIT License
Author : instana
Copyright MIT License
Author : instana
def task_response(self, message_id, data):
"""
When the host agent pastes us a task and we do it, this function is used to
respond with the results of the task.
"""
try:
response = None
payload = json.dumps(data)
logger.debug("Task response is %s: %s", self.__response_url(message_id), payload)
response = self.client.post(self.__response_url(message_id),
data=payload,
headers={"Content-Type": "application/json"},
timeout=0.8)
except (requests.ConnectTimeout, requests.ConnectionError):
logger.debug("task_response", exc_info=True)
except Exception:
logger.debug("task_response Exception", exc_info=True)
finally:
return response