本文整理汇总了Python中urllib3.exceptions.ConnectTimeoutError方法的典型用法代码示例。如果您正苦于以下问题:Python exceptions.ConnectTimeoutError方法的具体用法?Python exceptions.ConnectTimeoutError怎么用?Python exceptions.ConnectTimeoutError使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类urllib3.exceptions
的用法示例。
在下文中一共展示了exceptions.ConnectTimeoutError方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: connect
# 需要导入模块: from urllib3 import exceptions [as 别名]
# 或者: from urllib3.exceptions import ConnectTimeoutError [as 别名]
def connect(self):
logger.debug('[MyHTTPConnection] connect %s:%i', self.host, self.port)
try:
self._tor_stream = self._circuit.create_stream((self.host, self.port))
logger.debug('[MyHTTPConnection] tor_stream create_socket')
self.sock = self._tor_stream.create_socket()
if self._tunnel_host:
self._tunnel()
except TimeoutError:
logger.error('TimeoutError')
raise ConnectTimeoutError(
self, 'Connection to %s timed out. (connect timeout=%s)' % (self.host, self.timeout)
)
except Exception as e:
logger.error('NewConnectionError')
raise NewConnectionError(self, 'Failed to establish a new connection: %s' % e)
示例2: get_resource
# 需要导入模块: from urllib3 import exceptions [as 别名]
# 或者: from urllib3.exceptions import ConnectTimeoutError [as 别名]
def get_resource(self, resource, namespace="all"):
ret, resources = None, list()
try:
ret, namespaced_resource = self._call_api_client(resource)
except ApiException as ae:
self.logger.warning("resource autocomplete disabled, encountered "
"ApiException", exc_info=1)
except (NewConnectionError, MaxRetryError, ConnectTimeoutError):
self.logger.warning("unable to connect to k8 cluster", exc_info=1)
if ret:
for i in ret.items:
if namespace == "all" or not namespaced_resource:
resources.append((i.metadata.name, i.metadata.namespace))
elif namespace == i.metadata.namespace:
resources.append((i.metadata.name, i.metadata.namespace))
return resources
示例3: test_connection_timeout_fail
# 需要导入模块: from urllib3 import exceptions [as 别名]
# 或者: from urllib3.exceptions import ConnectTimeoutError [as 别名]
def test_connection_timeout_fail(self):
self._connect()
d = Deferred()
self.mock_agent.request.return_value = d
node_id = "http://otherhost"
uaid = "deadbeef000000000000000000000000"
self.proto.ps.uaid = uaid
connected = int(time.time())
res = dict(node_id=node_id, connected_at=connected, uaid=uaid)
self.proto._check_other_nodes((True, res))
d.errback(ConnectTimeoutError())
return d
示例4: _new_conn
# 需要导入模块: from urllib3 import exceptions [as 别名]
# 或者: from urllib3.exceptions import ConnectTimeoutError [as 别名]
def _new_conn(self):
logger.debug('[MyHTTPSConnection] new conn %s:%i', self.host, self.port)
try:
self._tor_stream = self._circuit.create_stream((self.host, self.port))
logger.debug('[MyHTTPSConnection] tor_stream create_socket')
return self._tor_stream.create_socket()
except TimeoutError:
logger.error('TimeoutError')
raise ConnectTimeoutError(
self, 'Connection to %s timed out. (connect timeout=%s)' % (self.host, self.timeout)
)
except Exception as e:
logger.error('NewConnectionError')
raise NewConnectionError(self, 'Failed to establish a new connection: %s' % e)
示例5: send
# 需要导入模块: from urllib3 import exceptions [as 别名]
# 或者: from urllib3.exceptions import ConnectTimeoutError [as 别名]
def send(self, request):
try:
proxy_url = self._proxy_config.proxy_url_for(request.url)
manager = self._get_connection_manager(request.url, proxy_url)
conn = manager.connection_from_url(request.url)
self._setup_ssl_cert(conn, request.url, self._verify)
request_target = self._get_request_target(request.url, proxy_url)
urllib_response = conn.urlopen(
method=request.method,
url=request_target,
body=request.body,
headers=request.headers,
retries=False,
assert_same_host=False,
preload_content=False,
decode_content=False,
)
http_response = botocore.awsrequest.AWSResponse(
request.url,
urllib_response.status,
urllib_response.headers,
urllib_response,
)
if not request.stream_output:
# Cause the raw stream to be exhausted immediately. We do it
# this way instead of using preload_content because
# preload_content will never buffer chunked responses
http_response.content
return http_response
except URLLib3SSLError as e:
raise SSLError(endpoint_url=request.url, error=e)
except (NewConnectionError, socket.gaierror) as e:
raise EndpointConnectionError(endpoint_url=request.url, error=e)
except ProxyError as e:
raise ProxyConnectionError(proxy_url=proxy_url, error=e)
except URLLib3ConnectTimeoutError as e:
raise ConnectTimeoutError(endpoint_url=request.url, error=e)
except URLLib3ReadTimeoutError as e:
raise ReadTimeoutError(endpoint_url=request.url, error=e)
except ProtocolError as e:
raise ConnectionClosedError(
error=e,
request=request,
endpoint_url=request.url
)
except Exception as e:
message = 'Exception received when sending urllib3 HTTP request'
logger.debug(message, exc_info=True)
raise HTTPClientError(error=e)
示例6: request
# 需要导入模块: from urllib3 import exceptions [as 别名]
# 或者: from urllib3.exceptions import ConnectTimeoutError [as 别名]
def request(self, url):
"""
Client request HTTP
:param str url: request uri
:return: urllib3.HTTPResponse
"""
if self._HTTP_DBG_LEVEL <= self.__debug.level:
self.__debug.debug_request(self._headers, url, self.__cfg.method)
try:
if self.__cfg.DEFAULT_SCAN == self.__cfg.scan:
response = self.__pool.request(self.__cfg.method,
helper.parse_url(url).path,
headers=self._headers,
retries=self.__cfg.retries,
assert_same_host=True,
redirect=False)
self.cookies_middleware(is_accept=self.__cfg.accept_cookies, response=response)
else:
response = PoolManager().request(self.__cfg.method, url,
headers=self._headers,
retries=self.__cfg.retries,
assert_same_host=False,
redirect=False)
return response
except MaxRetryError:
if self.__cfg.DEFAULT_SCAN == self.__cfg.scan:
self.__tpl.warning(key='max_retry_error', url=helper.parse_url(url).path)
pass
except HostChangedError as error:
self.__tpl.warning(key='host_changed_error', details=error)
pass
except ReadTimeoutError:
self.__tpl.warning(key='read_timeout_error', url=url)
pass
except ConnectTimeoutError:
self.__tpl.warning(key='connection_timeout_error', url=url)
pass
示例7: send
# 需要导入模块: from urllib3 import exceptions [as 别名]
# 或者: from urllib3.exceptions import ConnectTimeoutError [as 别名]
def send(self, request):
try:
proxy_url = self._proxy_config.proxy_url_for(request.url)
manager = self._get_connection_manager(request.url, proxy_url)
conn = manager.connection_from_url(request.url)
self._setup_ssl_cert(conn, request.url, self._verify)
request_target = self._get_request_target(request.url, proxy_url)
urllib_response = conn.urlopen(
method=request.method,
url=request_target,
body=request.body,
headers=request.headers,
retries=False,
assert_same_host=False,
preload_content=False,
decode_content=False,
chunked=self._chunked(request.headers),
)
http_response = botocore.awsrequest.AWSResponse(
request.url,
urllib_response.status,
urllib_response.headers,
urllib_response,
)
if not request.stream_output:
# Cause the raw stream to be exhausted immediately. We do it
# this way instead of using preload_content because
# preload_content will never buffer chunked responses
http_response.content
return http_response
except URLLib3SSLError as e:
raise SSLError(endpoint_url=request.url, error=e)
except (NewConnectionError, socket.gaierror) as e:
raise EndpointConnectionError(endpoint_url=request.url, error=e)
except ProxyError as e:
raise ProxyConnectionError(proxy_url=proxy_url, error=e)
except URLLib3ConnectTimeoutError as e:
raise ConnectTimeoutError(endpoint_url=request.url, error=e)
except URLLib3ReadTimeoutError as e:
raise ReadTimeoutError(endpoint_url=request.url, error=e)
except ProtocolError as e:
raise ConnectionClosedError(
error=e,
request=request,
endpoint_url=request.url
)
except Exception as e:
message = 'Exception received when sending urllib3 HTTP request'
logger.debug(message, exc_info=True)
raise HTTPClientError(error=e)